0

I am trying to create a new dataframe from a preexisting one. It will be grouped on the name field, and then should have 3 separate count columns. The columns are the count of each unique value for the type field.

name     type
Bob      A
Phil     B
Phil     B
James    C
Bob      C
Phil     C
James    B

This should turn into

name     count_a     count_b     count_c
Bob      1           0           1
Phil     0           2           1
James    0           1           1

I have tried using a pandas groupby function, but cant figure out how to get the count of each rather than a count of the whole column.

Jack Walsh
  • 562
  • 4
  • 14

0 Answers0