1

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.

Redratz
  • 136
  • 7
  • So do you need just the last `elo` rating of a racer? Do you need accumulative `elo` or? Can you provide some examples / expected results? – Danail Petrov Dec 27 '20 at 18:36
  • I have the elo for the racer after each race, the issue is I can't figure out how to replace the next occurence of that racer's elo with their update elo after the previous race. – Redratz Dec 27 '20 at 18:41
  • So where do you want to update the elo? if, for example, a racer is with a new elo of 1700, do you want all the previous `elo` ranks for this racer to be changed to the latest `elo` rating or what is what you're trying to achieve? – Danail Petrov Dec 27 '20 at 18:44
  • I want to change that racers elo for the next race they are in to reflect their new elo. – Redratz Dec 27 '20 at 18:52
  • I think I might have a solution, I'll update if it works, the programs running right now. – Redratz Dec 27 '20 at 18:52
  • it's alot of guessing here.. I want to help, but the information is quite unclear. For example what does "next race" mean? How do you populate the data to the dataframe? where are you getting it from? Can you provide samples of all the inputs and what is the expected output? Check this one https://stackoverflow.com/questions/20109391/how-to-make-good-reproducible-pandas-examples – Danail Petrov Dec 27 '20 at 18:54

1 Answers1

1

You can use DataFrame.itertuples ()

for row in df.itertuples():
    df.set_value(row.index, YOUR_VALUE_UPDATED, row.elo)
a-boubekri
  • 46
  • 2