In a dataframe such as
df = pd.DataFrame({'A' : ['a','a','b','b','a'],
'B' : [1,22,8,3,3]})
I need to partition data by A
and find max
of B
in each partition and save the result in a new column C
df = pd.DataFrame({'A' : ['a','a','b','b','a'],
'B' : [1,22,8,3,3],
'C' : [22, 22 , 8, 8 , 22]})
I have tried
df['C'] = df.groupby(['A'])['B'].max()
but this simply only adds a Nan
column.