I have a dataframe with 50 data points per month. I'd like to calculate the median value for each decile within each month. In my groupby call I lead with the date, then qcut. But qcut calculates the bins over the whole dataset, not by month. Here's what I have so far:
import numpy as np
import pandas as pd
datecol = pd.date_range('12/31/2018','12/31/2019', freq='M')
for ii in range(0,49):
datecol = datecol.append(pd.date_range('12/31/2018','12/31/2019', freq='M'))
datecol = datecol.sort_values()
df = pd.DataFrame(np.random.randn(len(datecol), 1), index=datecol, columns=['Data'])
dfg = df.groupby([df.index, pd.qcut(df['Data'], 10)])['Data'].median()
I've tried to run a qcut on the monthly grouping, but that hasn't worked.