close

[Solved] TypeError: Only valid with DatetimeIndex, TimedeltaIndex or PeriodIndex, but got an instance of ‘RangeIndex’ and I can’t figure out why

Hello Guys, How are you all? Hope You all Are Fine. Today I get the following error TypeError: Only valid with DatetimeIndex, TimedeltaIndex or PeriodIndex, but got an instance of ‘RangeIndex’ and I can’t figure out why in python. So Here I am Explain to you all the possible solutions here.

Without wasting your time, Let’s start This Article to Solve This Error.

How TypeError: Only valid with DatetimeIndex, TimedeltaIndex or PeriodIndex, but got an instance of ‘RangeIndex’ and I can’t figure out why Error Occurs?

Today I get the following error TypeError: Only valid with DatetimeIndex, TimedeltaIndex or PeriodIndex, but got an instance of ‘RangeIndex’ and I can’t figure out why in python.

How To Solve TypeError: Only valid with DatetimeIndex, TimedeltaIndex or PeriodIndex, but got an instance of ‘RangeIndex’ and I can’t figure out why Error ?

  1. How To Solve TypeError: Only valid with DatetimeIndex, TimedeltaIndex or PeriodIndex, but got an instance of 'RangeIndex' and I can't figure out why Error ?

    To Solve TypeError: Only valid with DatetimeIndex, TimedeltaIndex or PeriodIndex, but got an instance of 'RangeIndex' and I can't figure out why Error Convert column date to datetimes and add parameter on to resample:

  2. TypeError: Only valid with DatetimeIndex, TimedeltaIndex or PeriodIndex, but got an instance of 'RangeIndex' and I can't figure out why

    To Solve TypeError: Only valid with DatetimeIndex, TimedeltaIndex or PeriodIndex, but got an instance of 'RangeIndex' and I can't figure out why Error Convert column date to datetimes and add parameter on to resample:

Solution 1

Convert column date to datetimes and add parameter on to resample:

df['date'] = pd.to_datetime(df['date'])
weekly_summary = df.story_point.resample('W', on='date').sum()

If need new column:

weekly_summary['weekly'] = df.story_point.resample('W', on='date').transform('sum')

Or create DatetimeIndex:

df['date'] = pd.to_datetime(df['date'])
df = df.set_index('date') 
weekly_summary = df.story_point.resample('W').sum()

If need new column:

weekly_summary['weekly'] = df.story_point.resample('W').transform('sum')

Summery

It’s all About this issue. Hope all solution helped you a lot. Comment below Your thoughts and your queries. Also, Comment below which solution worked for you? Thank You.

Also, Read