Search code examples
pandasdataframepandas-groupbysklearn-pandas

how to unstack a series


I grouped a data like below which returns a series and column 2 is multi layers

grouped = data.groupby(['Column_1','Column_2','Column_3']).size()

Now I want to unstack only Column_2 which is a categorical data and have each category as a column. I am able to easily achieve this with only two columns.

Please any help will be greatly appreciated


Solution

  • As answered by Manakin, grouped.unstack(1) worked for me.