I am looking for a way to copy the result of an aggregate call to each row in a dataframe.
I am currently doing it like this:
tmp = df.groupby('somekey').col_to_sum.sum().reset_index()
df = df.merge(tmp, how='left', on='somekey')
This gives me the result I want:
tmp
is a series of the sum for each value of somekey
and the merge then "copies it" to each row in the original df
(so each row contains the sum value).
Is there a shorter way to achieve the same result?