futurelj
futurelj

Reputation: 273

Combine the dataframe in Pandas

I have a data frame:

>>> data    
    Name  Score
0    a      3
1    b      2
2    a      1
3    c      4
4    c      5
5    d      3

I want to combine the rows with same name, adding score rows, so I want to get the following result:

    Name  Score
0    a      4
1    b      2    
2    c      9   
3    d      3

Is there an effective solution?

Upvotes: 1

Views: 50

Answers (1)

G.S
G.S

Reputation: 402

data.groupby('Name').sum()['Score'].reset_index()

Upvotes: 2

Related Questions