I have the following DataFrame:
df = pd.DataFrame({
'Buyer': 'Carl Mark Carl Joe Joe Carl'.split(),
'Trades': [1,3,5,8,9,3],
'Date' : [
DT.datetime(2013,1,1,13,0),
DT.datetime(2013,1,1,13,5),
DT.datetime(2013,1,1,20,0),
DT.datetime(2013,1,2,10,0),
DT.datetime(2013,1,2,12,0),
DT.datetime(2013,1,2,14,0),
]})
Now I would like to group by the day and calculate the mean number of trades for each trader. To do so, I use the groupby function:
gr = df.groupby([df.Date.map(lambda d: d.date()), 'Buyer']).mean()
Is there any possibility to convert the resulting 'gr' DataFrame into a DataFrame with a PeriodIndex so that I can use the resample function to calculate weekly and monthly averages?
Important: I need to resample the 'gr' Dataframe not the original 'df'
I would deeply appreciate any help.
Thank you
Andy