This question already has an answer here:
Given the following dataframe:
col_a | col_b_tosum
b | 5
b | 5
b | 1
c | 6
c | 3
a | 2
a | 2
I would like to show the sum of each col_ group on all rows, like this:
col_a | col_b_tosum | group_sum
b | 5 11
b | 5 11
b | 1 11
c | 6 9
c | 3 9
a | 2 4
a | 2 4
Use
groupby
withtransform
:Output: