I have a Pandas DataFrame with a daily DatetimeIndex. I am trying to apply the Resample method to sum the values into a monthly series like this:
>>> aggVols.resample('M',axis=1).sum()
But when I try this I get the error
TypeError: Only valid with DatetimeIndex or PeriodIndex
I noticed that the frequency of the index of the object is not set (None).
>>>aggVols.index
<class 'pandas.tseries.index.DatetimeIndex'>
[2016-01-04, ..., 2016-07-01]
Length: 130, Freq: None, Timezone: None
So I first set the frequency to daily (business day) and reset the index so that I can apply resample:
>>> aggVols = aggVols.reindex(aggVols.asfreq('B').index)
>>> aggVols.index
<class 'pandas.tseries.index.DatetimeIndex'>
[2016-01-04, ..., 2016-07-01]
Length: 130, Freq: B, Timezone: None
But I am still getting the same error our of the resample function:
TypeError: Only valid with DatetimeIndex or PeriodIndex
What is wrong with the index? Why is it not valid? I get the same error if I set the frequency to D.
Thanks!