From a dataframe df I want to update the value of a column Points for the top 3 values of another column Time after sorting the Time column in ascending order, such that
df['Points'] = df['Points'] * 1.3 for the first row (smallest Time)
df['Points'] = df['Points'] * 1.2 for the second row (second smallest Time)
df['Points'] = df['Points'] * 1.1 for the third row (third smallest Time) rounded to the nearest integer.
and Points for all other rows remains the same.
I have to do this for every unique value for a third column value Challenge. How can I do this?
So, I need PointsA instead of Points from below -
Challenge Team Time Points PointsA
A 1 2019-11-05 23:00:43.07589 200 260
B 3 2019-11-05 22:10:55.07589 100 130
A 5 2019-11-05 23:05:43.07589 200 240
A 7 2019-11-05 23:07:33.07589 200 220
B 10 2019-11-05 22:20:13.07589 100 120
C 4 2019-11-06 00:05:22.07589 50 65
A 4 2019-11-05 23:18:23.07589 200 200
I've tried something like -
for challenge in df['Challenge'].unique():
df[df['Challenge'] == challenge].sort_values('Time', ascending=True).head(1)['Points'] *= 1.3
but that doesn't seem to work.