I am trying to calculate a new column which contains maximum values for each of several groups. I\'m coming from a Stata background so I know the Stata code would be somethi
Use groupby + transform:
df['max'] = df.groupby('group')['odds'].transform('max')
This is equivalent to the verbose:
maxima = df.groupby('group')['odds'].max()
df['max'] = df['group'].map(maxima)
The transform method aligns the groupby result to the groupby indexer, so no explicit mapping is required.