0

I have a data frame similar to this one.

Name    Asset
A       2
B       5
C       2
B       3
A       4
A       5
C       1

Now I want to sum up all assets == A, B and C. At the end I want to create a new data frame and store the overall sum in one row together with the name. Like this:

Name    Asset
A       11
B       8
C       3

Do you now a nice and easy way how to do the job?

Bahlsen
  • 177
  • 1
  • 9

1 Answers1

1

You simply need to use pandas.DataFrame.groupby, applying a sum. Try this code:

df.groupby(['Name']).sum()

and gives:

      Asset
Name       
A        11
B         8
C         3
Massifox
  • 4,369
  • 11
  • 31