I have this dataframe:
nome code tipo score
Alexandre AAA Frads 4000
Alexandre AAA Memb 10000
Alexandre AAA Memb 20000
Bruno BBB Dans 10000
Bruno BBB Grap 4000
Values available in this Google Sheets
I need to create a new column summing the rows with same nome
and code
where tipo = 'Memb'
, in a way that it looks like this:
I tried groupby
with transform('sum')
however it is getting me the wrong result.
df['score'].loc[df['tipo'] == "Memb"]=df[['nome','code','score']].groupby(['nome','code'])['score'].transform('sum')
What am I missing?