The default behavior of pandas groupby is to turn the group by columns into the index and remove them from the list of columns of the dataframe. For instance, say I have a dataFrame with these columns
col1|col2|col3|col4
if I apply a groupby say with columns col2 and col3 this way
df.groupby(['col2','col3']).sum()
The dataframe df no longer has the ['col2','col3'] in the list of columns. They are automatically turned into the indices of the resulting dataframe.
My question is how can I perform groupby on a column and yet keep that column in the dataframe?