简体   繁体   English

类型错误:仅对 DatetimeIndex、TimedeltaIndex 或 PeriodIndex 有效,但得到了“RangeIndex”的实例

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

Here's what my dataframe looks like:这是我的数据框的样子:

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

The years goes all the way to 2019 and I'm trying to resample it to individual years.这些年一直到 2019 年,我正试图将其重新采样到个别年份。

I had converted the Date column to Datetime as shown below.我已将日期列转换为日期时间,如下所示。

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

The problem is when I'm trying to resample:问题是当我尝试重新采样时:

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

I get the error message of:我收到以下错误消息:

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

resample requires the index to be datetime format. resample要求索引为日期时间格式。 So if you select your date column to be the index it should work.因此,如果您选择日期列作为索引,它应该可以工作。 You can do that by using set_index .您可以使用set_index来做到这一点

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Pandas重采样:TypeError:仅对DatetimeIndex,TimedeltaIndex或PeriodIndex有效,但得到'RangeIndex'的实例 - Pandas Resampling: TypeError: Only valid with DatetimeIndex, TimedeltaIndex or PeriodIndex, but got an instance of 'RangeIndex' Pandas dataframe.resample TypeError '仅对 DatetimeIndex、TimedeltaIndex 或 PeriodIndex 有效,但获得了“RangeIndex”实例 - Pandas dataframe.resample TypeError 'Only valid with DatetimeIndex, TimedeltaIndex or PeriodIndex, but got an instance of 'RangeIndex' TypeError:仅对 DatetimeIndex、TimedeltaIndex 或 PeriodIndex 有效,但得到了“RangeIndex”的实例,我不知道为什么 - TypeError: Only valid with DatetimeIndex, TimedeltaIndex or PeriodIndex, but got an instance of 'RangeIndex' and I can't figure out why 类型错误:如何修复仅对 DatetimeIndex、TimedeltaIndex 或 PeriodIndex 有效,但得到了“Index”的实例 - TypeError: How to fix Only valid with DatetimeIndex, TimedeltaIndex or PeriodIndex, but got an instance of 'Index' Pandas TypeError:仅对DatetimeIndex,TimedeltaIndex或PeriodIndex有效,但具有“ Int64Index”的实例 - Pandas TypeError: Only valid with DatetimeIndex, TimedeltaIndex or PeriodIndex, but got an instance of 'Int64Index' Python datetime 仍然给出“TypeError: Only valid with DatetimeIndex, TimedeltaIndex or PeriodIndex, but got an instance of 'Index'” - Python datetime still gives "TypeError: Only valid with DatetimeIndex, TimedeltaIndex or PeriodIndex, but got an instance of 'Index'" TypeError:仅当dtype为datetime64 [ns]时对DatetimeIndex,TimedeltaIndex或PeriodIndex有效 - TypeError: Only valid with DatetimeIndex, TimedeltaIndex or PeriodIndex when dtype is datetime64[ns] Pandas 重采样错误:仅对 DatetimeIndex、TimedeltaIndex 或 PeriodIndex 有效 - Pandas Resampling error: Only valid with DatetimeIndex, TimedeltaIndex or PeriodIndex pandas 不能按日期分组,仅对 DatetimeIndex、TimedeltaIndex 或 PeriodIndex 有效,但 - pandas cannot group by date, Only valid with DatetimeIndex, TimedeltaIndex or PeriodIndex, but 如何修复TypeError:仅对DatetimeIndex有效 - how to fix TypeError: Only valid with DatetimeIndex
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM