TypeError: 只有 DatetimeIndex、TimedeltaIndex 或 PeriodIndex 才有效,但却得到 'RangeIndex' 实例。

2024-10-03 02:48:14 发布

您现在位置:Python中文网/ 问答频道 /正文

以下是我的数据帧的外观:

intrate.head()
Out[83]: 
         Date  UNRATE
0  1954-07-01    0.80
1  1954-08-01    1.22
2  1954-09-01    1.06
3  1954-10-01    0.85
4  1954-11-01    0.83

这些年一直持续到2019年,我正在尝试将其重新采样到个别年份

我已经将Date列转换为Datetime,如下所示

Out[86]: 
Date      datetime64[ns]
UNRATE           float64
dtype: object

问题是当我尝试重新取样时:

intratey = intrate.resample('A').ffill()

我收到错误消息:

TypeError: Only valid with DatetimeIndex, TimedeltaIndex or PeriodIndex, but got an instance of 'RangeIndex'

Tags: 数据datetimedateobjectouthead外观ns