Reputation: 136
I have a pandas df containing a race_id, a racer_id, and an elo. I'm attempting to update the elos of each racer after each race.
The data looks like this:
race_id | racer_id | elo |
---|---|---|
0 | 1 | 1500 |
0 | 2 | 1500 |
0 | 3 | 1500 |
0 | 4 | 1500 |
1 | 1 | 1500 |
1 | 2 | 1500 |
1 | 3 | 1500 |
1 | 4 | 1500 |
I'm trying to update the elo of the racer after the race occurs. i.e. in the above table, after race_id 0, the elos for race_id 1 would be changed to reflect the outcome of race_id 0.
Basically, I can't figure out how to get pandas to update the next occurrence of the racer_id with their new elo.
I should also clarify that this is a dataset of tens of thousands of racers and races. So it could be multiple races before that same racer appears again. The data is sorted by race_id.
Upvotes: 1
Views: 168
Reputation: 46
You can use DataFrame.itertuples ()
for row in df.itertuples():
df.set_value(row.index, YOUR_VALUE_UPDATED, row.elo)
Upvotes: 1