I have a dataframe where I am doing groupby on 3 columns and aggregating the sum and size of the numerical columns. After running the code
df = pd.DataFrame.groupby(['year','cntry', 'state']).agg(['size','sum'])
I am getting something like below:
Now I want to split my size sub columns from main columns and create only single size column but want to keep the sum columns under main column headings. I have tried different approaches but not successful. These are the methods I have tried but unable to get things working for me:
How to count number of rows in a group in pandas group by object?
Converting a Pandas GroupBy object to DataFrame
Will be grateful to if anyone can help me with this one.
Regards,