1

After grouping the column of the pandas dataframe how to do sum of another column of a dataframe based on the groups created.

df = df.groupby(by=['First'])

My dataframe:

First  Second

A      5
       6
       10
B      4
       5

expected dataframe:

First  Second

A      21
B      9

1 Answers1

1
df= df.groupby(['First'])['Second'].sum().reset_index()

I noticed you are missing a ' in your code, it might have been causing you issues before.

MBA Coder
  • 374
  • 1
  • 3
  • 13