Pivoting tables in a pandas dataframe

后端 未结 3 1605
萌比男神i
萌比男神i 2021-01-06 05:11

I have a requirement where in I am trying to count the values and Put them in the pivot table.

This is my dataframe,

  Cola        Colb          
 Ap         


        
3条回答
  •  暗喜
    暗喜 (楼主)
    2021-01-06 05:31

    Using my favourite: pd.crosstab

    df = pd.crosstab(df.Cola, df.Colb)
    print(df)
    
    Colb    Rippened  UnRippened
    Cola                        
    Apple          1           1
    Mango          0           1
    Orange         1           0
    

提交回复
热议问题