I have the code below that creates new columns in my dataframe for median sold and std sold. The problem I have is that I don't want the multi-index output. How can I flatten the output like the desired output example below? Or is there a way to just create the new columns as aggregations of sold without creating the multi index in the first place.
Maybe something like in sql:
select Month, M_day, median(sold) as median, std(sold) as std from month_df group by Month, M_day
Code:
month_df=month_df[['Month','M_day','sold']].groupby(['Month','M_day']).agg(['median','std'])
print(month_df.head())
Output:
sold
median std
Month M_day
1 2 12.0 13.719555
3 5.0 11.508762
4 12.0 12.907761
5 6.0 14.371283
6 12.0 7.859340
desired output:
Month M_day median std
1 2 12.0 13.719555
3 5.0 11.508762
4 12.0 12.907761
5 6.0 14.371283
6 12.0 7.859340