Python熊猫DateTimeIndex

詹姆士

在DataFrame的DateTimeIndex下面。夏/冬时区为“美国/东部”,但是记录的时间戳为“欧洲/伦敦”。我正在尝试重新编制索引,以实现完整的时间序列。

DatetimeIndex(['1993-10-24 21:00:00', '1993-10-25 21:00:00',
               '1993-10-26 21:00:00', '1993-10-27 21:00:00',
               '1993-10-28 21:00:00', '1993-10-31 22:00:00',
               '1993-11-01 22:00:00', '1993-11-02 22:00:00',
               '1993-11-03 22:00:00', '1993-11-04 22:00:00'],
              dtype='datetime64[ns]', name=u'TIME', freq=None)

如何在不弄乱小时元素的情况下重新索引以上内容?

海盗
tidx = pd.DatetimeIndex(
    [
        '1993-10-24 21:00:00', '1993-10-25 21:00:00',
        '1993-10-26 21:00:00', '1993-10-27 21:00:00',
        '1993-10-28 21:00:00', '1993-10-31 22:00:00',
        '1993-11-01 22:00:00', '1993-11-02 22:00:00',
        '1993-11-03 22:00:00', '1993-11-04 22:00:00'],
    dtype='datetime64[ns]', name=u'TIME', freq=None
)

ts = tidx.to_series().dt.hour.resample('D').last().ffill().rename_axis('date')
ts.index + pd.to_timedelta(ts.values, unit='H')

DatetimeIndex(['1993-10-24 21:00:00', '1993-10-25 21:00:00',
               '1993-10-26 21:00:00', '1993-10-27 21:00:00',
               '1993-10-28 21:00:00', '1993-10-29 21:00:00',
               '1993-10-30 21:00:00', '1993-10-31 22:00:00',
               '1993-11-01 22:00:00', '1993-11-02 22:00:00',
               '1993-11-03 22:00:00', '1993-11-04 22:00:00'],
              dtype='datetime64[ns]', freq=None)

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章