0

How to store the dataframe from the output from pandas group by as something like output 2 given below without displaying both category in the first column (i think it is the index).

The below code output is given in the output 1 but I need to create something like output 2

df1 = (df.groupby(['a_category', 'b_category' ]). size(). unstack ()

Output1:

df1:

b_category        no     yes
a_category
A1                10     15
A2                20     22
A3                11     16
A4                12     26

Output :

df1:

a_category        no     yes
A1                10     15
A2                20     22
A3                11     16
A4                12     26
Community
  • 1
  • 1
user3762120
  • 256
  • 2
  • 12

0 Answers0