TypeError:仅对DatetimeIndex、TimedeltaIndex或PeriodIndex有效,但获得了“Index”的实例`

2024-06-16 10:32:02 发布

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

fundos_btg_2017_return_diario.reset_index(level=0, inplace=True)

`fundos_btg_2017_return_diario`['DT_COMPTC'] = pd.to_datetime(fundos_btg_2017_return_diario['DT_COMPTC'])

fundos_btg_2017_return_diario=fundos_btg_2017_return_diario.set_index('DT_COMPTC').sort_index(ascending=True,inplace = False  )

teste = fundos_btg_2017_return_diario.resample('M').pad()

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

我想按月份排序,添加每月每一天的值并显示第1个月-所有天的值 我在几个文件中有数千个数据,所以一次性解决方案对我没有帮助

示例

DT_COMPTC      ID        ID2    ID3  
2017-01-02    n/a       n/a    n/a
2017-01-04    1.0009   1.0009  3.33
2017-01-09    00.002   1.0009  2.12
2017-02-01     0.34    2.13   1.89
...
... 

Tags: totruedatetimeindexreturndtlevelpd