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
2
  • I think need df1 = (df.groupby(['a_category', 'b_category' ]). size(). unstack().reset_index().rename_axis(None, axis=1) Commented Feb 9, 2018 at 14:14
  • Yes jezrael. Thanks for your answer. Commented Feb 10, 2018 at 0:40

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.