我有一个数据框,其索引也包含小时:第二个:...但我只是想让它包含年,月,日的日期。将DateTimeindex转换为仅包含年,小时和天不包含时间信息
索引是否可以仍然是DateTimeIndex但只包含年,月,日?
目前的指数看起来像:
my_index = DatetimeIndex(['2017-08-25', '2017-08-24', '2017-08-23', '2017-08-22',
'2017-08-21', '2017-08-20', '2017-08-19', '2017-08-18',
'2017-08-17', '2017-08-16',
...
'2015-07-19', '2015-07-18', '2015-07-17', '2015-07-16',
'2015-07-15', '2015-07-14', '2015-07-13', '2015-07-12',
'2015-07-11', '2015-07-10'],
dtype='datetime64[ns]', length=778, freq=None)
我可以这样做:
only_date_index = [el.date() for el in my_index]
不过,如果我想使用的重采样功能的熊猫我的错误: 类型错误:只有有效与DatetimeIndex,TimedeltaIndex或PeriodIndex,但有一个'索引'的实例。
尝试'.normalize()'它将使次去午夜,我相信'DateTimeIndex'所需要的时间 – Deckerz