pandas 无法比较偏移天真和偏移感知日期时间 [英] pandas can't compare offset-naive and offset-aware datetimes
本文介绍了pandas 无法比较偏移天真和偏移感知日期时间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有这样的 df:
df['Time']
2017-08-06 11:00:00+00:00
2017-08-08 15:00:00+00:00
2017-08-10 04:00:00+00:00
2017-08-12 23:00:00+00:00
2017-08-08 15:00:00+00:00
我想用条件切片
mask1=df['Time'] > datetime.datetime.strptime('2017-08-12', "%Y-%m-%d")
我收到类似
无法比较初始偏移量和感知偏移量的日期时间
can't compare offset-naive and offset-aware datetimes
不知何故,我必须将 df['Time']
转换为 offset-naive.
请帮我解决这个问题.
Somehow I have to convert df['Time']
to offset-naive.
Please help me fix this.
推荐答案
看来你需要:
df['Time'] = df['Time'].dt.tz_localize(None)
或者:
df['Time'] = df['Time'].dt.tz_convert(None)
或者:
df['Time'] = df['Time'].astype('datetime64[ns]')
另见 tz 感知数据类型代码>
.
这篇关于pandas 无法比较偏移天真和偏移感知日期时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文