I have two dataframes
A B C
1 John
2 Mike
3 David
X Y z
1 Mike 100
2 Mike 200
3 John 300
4 David 400
5 David 500
I want to fill C column with the sum of Z corresponding to each name in Y.
The result should look like below:
A B C
1 John 300
2 Mike 300
3 David 900
I did it by creating a pivot using groupby, then merging it, however I would like to know if there's an elegant and faster method of doing it.