0

suppose I have columns in a dataframe like this :

id        value
 a           2 
 a           1  
 b           8
 a           0  
 a           2

I have thousands of ids like these. I want to sum all the values with the same id so that I get a dataframe like :

a   5
b   8

How do I do this in pandas?

Sam
  • 352
  • 2
  • 4
  • 22

1 Answers1

2

You should use .groupby

df.groupby('id').sum()
iDrwish
  • 3,085
  • 1
  • 15
  • 24