0

I want to aggregate multiple rows in a dataset. However, the usual functions I found on the net are "sum()" and "mean()".

I have How can I aggregate multiple rows:

Movie | Comedy | Horror | Drama
A         1        0        0
A         0        0        1    
B         0        1        0
B         0        0        1

to

Movie | Comedy | Horror | Drama
A         1        0        1
B         0        1        1
  • It's not clear why you don't want to use `sum` here. What is the problem with that? – cs95 Sep 04 '18 at 23:20

1 Answers1

1

Use groupby

df.groupby('Movie', as_index=False).sum()

output:

Movie   Comedy  Horror  Drama           
   A      1       0       1
   B      0       1       1
Abhi
  • 4,068
  • 1
  • 16
  • 29