0

I am new to python and working on data analysis using pandas, I have a dataframe similar to one below,

col1 col2
a     10
b     20
a     30
a     15
c     10
b     10

Need to find sum of all values for col2 for each unique value in col1

Something like this:

a  55
b  30
c  10
Ralf Stubner
  • 26,263
  • 3
  • 40
  • 75
Somnath
  • 49
  • 5

1 Answers1

0

df.groupby(['col1']).agg(['sum']) .. this should work

else df.groupby(['col1'])['col2'].sum()

Soubhik Banerjee
  • 421
  • 4
  • 8
  • 17