【发布时间】:2020-03-24 01:26:58
【问题描述】:
我有两个时区感知 pandas 日期时间时间戳。当我减去它们时,我得到了错误:
TypeError: Timestamp subtraction must have the same timezones or no timezones
第一个是从转换到pandas datetime:
start_time = pd.to_datetime(dt.datetime(2019, 6, 28, 0, 52, 57, tzinfo=dt.timezone.utc))
第二个来自 DataFrame 索引,如下所示:
>> phase_df.index[0]
Timestamp('2019-06-28 00:52:30.000130+0000', tz='UTC')
确认它们是同一类型:
>> type(phase_df.index[0]), type(start_time)
(pandas._libs.tslibs.timestamps.Timestamp,
pandas._libs.tslibs.timestamps.Timestamp)
【问题讨论】: