I have a dataset that looks like:
sp_data.head()
Out[21]:
Date Open High Low Close Adj Close Volume
0 1927-12-30 17.660000 17.660000 17.660000 17.660000 17.660000 0
1 1928-01-03 17.760000 17.760000 17.760000 17.760000 17.760000 0
2 1928-01-04 17.719999 17.719999 17.719999 17.719999 17.719999 0
3 1928-01-05 17.549999 17.549999 17.549999 17.549999 17.549999 0
4 1928-01-06 17.660000 17.660000 17.660000 17.660000 17.660000 0
which contains daily data, and I would like to get the returns per week, per month, per 3, 6 months etc. I tried the following:
sp_data_daily_returns = sp_data['Close'].pct_change()
sp_data_monthly_returns = sp_data['Close'].resample('M').ffill().pct_change()
but I am getting this error:
TypeError: Only valid with DatetimeIndex, TimedeltaIndex or PeriodIndex, but got an instance of 'RangeIndex'
How can I fix that?