I am trying to compute a new column that contains the maximum values for each of several groups. I am coming from the Stata background, so I know that the Stata code will be something like this:
by group, sort: egen max = max(odds)
For instance:
data = {'group' : ['A', 'A', 'B','B'],
'odds' : [85, 75, 60, 65]}
Then I would like it to look like this:
group odds max
A 85 85
A 75 85
B 60 65
B 65 65
In the end, I try to form a column that accepts 1/(max-min) * oddswhere maxand minfor each group.
Vicki source
share