Jalu
Jalu

Reputation: 41

Pandas DataFrame - summing rows by multiple column values

I am working on a Pandas dataframe in Python, i would like to do following rearrangement of the dataset :

img

I tried using for loops, but I wonder if there is any simpler solution using Pandas - i couldn't find anything more elegant.

Upvotes: 0

Views: 149

Answers (1)

ansev
ansev

Reputation: 30920

Use :

df.groupby(['Year','Sex'],as_index=False).sum()

Upvotes: 2

Related Questions