相关疑难解决方法(0)

将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)
Run Code Online (Sandbox Code Playgroud)

我可以:

only_date_index = [el.date() for el in my_index]
Run Code Online (Sandbox Code Playgroud)

但是如果我想在pandas中使用resample函数,我会得到错误:TypeError:只对DatetimeIndex,TimedeltaIndex或PeriodIndex有效,但得到了一个'Index'实例.

python pandas

2
推荐指数
1
解决办法
712
查看次数

标签 统计

pandas ×1

python ×1