Pandas groupby(),agg() - how to return results without the multi index? Pandas groupby(),agg() - how to return results without the multi index? python python

Pandas groupby(),agg() - how to return results without the multi index?


Below call:

>>> gr = df.groupby(['EVENT_ID', 'SELECTION_ID'], as_index=False)>>> res = gr.agg({'ODDS':[np.min, np.max]})>>> res    EVENT_ID SELECTION_ID ODDS                               amin amax0  100429300      5297529   18   251  100429300      5297559   30   38

returns a frame with mulit-index columns. If you do not want columns to be multi-index either you may do:

>>> res.columns = list(map(''.join, res.columns.values))>>> res    EVENT_ID  SELECTION_ID  ODDSamin  ODDSamax0  100429300       5297529        18        251  100429300       5297559        30        38