为了账号安全,请及时绑定邮箱和手机立即绑定

pandas.Timestamp的时间差着8个小时,如何解决时区的问题?

pandas.Timestamp的时间差着8个小时,如何解决时区的问题?

饮歌长啸 2019-02-07 17:16:10
 ~\Desktop  λ ip Python 3.6.7rc2 (v3.6.7rc2:4893861ab5, Oct 13 2018, 17:34:23) [MSC v.1900 64 bit (AMD64)] Type 'copyright', 'credits' or 'license' for more information IPython 7.2.0 -- An enhanced Interactive Python. Type '?' for help.In [1]: import pandas as pdIn [2]: ts = pd.Timestamp(2017,6,19)In [3]: tsOut[3]: Timestamp('2017-06-19 00:00:00')In [4]: tss = ts.timestamp()In [5]: tssOut[5]: 1497830400.0In [6]: from datetime import datetimeIn [7]: datetime.fromtimestamp(tss)Out[7]: datetime.datetime(2017, 6, 19, 8, 0)In [8]:就这样,很简单的代码,现在的解决方式是求出timestamp后减去8个小时,有没有其他的解决办法?
查看完整描述

1 回答

?
FFIVE

TA贡献1797条经验 获得超6个赞

在Pandas中提供了tz_localizetz_convert这2个函数,其中前者用于将时间戳转换为本地时间,而后者可以用于任意时区的转换。

查看完整回答
反对 回复 2019-02-21
  • 1 回答
  • 0 关注
  • 2385 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号