import pandas as pd
elo_history = pd.read_csv("C:\\Users\\chris\\Documents\\Datasets\\FFL\\elo_history.csv")
team_list = list(elo_history.team_1.unique())
team_list
['CHRIS', 'ANDREW', 'STEVE', 'MATT', 'KYLE', 'CARLEN', 'NATHAN', 'DREW', 'SAM', 'DYLAN', 'NICK', 'JASON', 'NOAH']
dates = list(elo_history.date.unique())
dates.insert(0, "2014-00")
elo_dict = {}
for i in team_list:
elo_dict[i] = [0] * len(dates)
curr_date = ""
date_index = 0
for index,row in elo_history.iterrows():
if row["date"] != curr_date:
curr_date = row["date"]
date_index += 1
elo_dict[row["team_1"]][date_index] = round(row["team1_elo_post"])
elo_dict[row["team_2"]][date_index] = round(row["team2_elo_post"])
# Add initial rating value of 1500 prior to team's first result.
for i in team_list:
for index,j in enumerate(elo_dict[i]):
if (j != 0):
elo_dict[i][index - 1] = 1500
break
# Replace values of 0 (due to playoff byes) with team's current rating value.
for i in team_list:
for index,j in enumerate(elo_dict[i]):
if (j == 0):
if (index > 0) & (index < len(elo_dict[i]) - 1):
if (elo_dict[i][index - 1] != 0) & (elo_dict[i][index + 1] != 0):
elo_dict[i][index] = elo_dict[i][index - 1]
elo_history
date | team_1 | team_2 | win | team1_elo_pre | team2_elo_pre | team1_elo_post | team2_elo_post | |
---|---|---|---|---|---|---|---|---|
0 | 2014-01 | CHRIS | CARLEN | 0 | 1500.000000 | 1500.000000 | 1485.000000 | 1515.000000 |
1 | 2014-01 | ANDREW | KYLE | 0 | 1500.000000 | 1500.000000 | 1485.000000 | 1515.000000 |
2 | 2014-01 | STEVE | DREW | 1 | 1500.000000 | 1500.000000 | 1515.000000 | 1485.000000 |
3 | 2014-01 | MATT | NATHAN | 1 | 1500.000000 | 1500.000000 | 1515.000000 | 1485.000000 |
4 | 2014-02 | MATT | CHRIS | 1 | 1515.000000 | 1485.000000 | 1528.708005 | 1471.291995 |
... | ... | ... | ... | ... | ... | ... | ... | ... |
559 | 2021-15 | ANDREW | STEVE | 1 | 1566.736021 | 1544.313236 | 1580.769293 | 1530.279964 |
560 | 2021-15 | NICK | CHRIS | 0 | 1524.258537 | 1642.915931 | 1514.191088 | 1652.983380 |
561 | 2021-15 | JASON | SAM | 0 | 1483.865477 | 1506.451432 | 1469.839220 | 1520.477689 |
562 | 2021-15 | DYLAN | KYLE | 0 | 1440.436529 | 1486.708300 | 1427.422514 | 1499.722315 |
563 | 2021-15 | MATT | NOAH | 1 | 1368.148791 | 1492.111812 | 1388.284599 | 1471.976003 |
564 rows × 8 columns
df = pd.DataFrame({"DATE" : dates} | elo_dict)
df.tail()
DATE | CHRIS | ANDREW | STEVE | MATT | KYLE | CARLEN | NATHAN | DREW | SAM | DYLAN | NICK | JASON | NOAH | |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
112 | 2021-11 | 1644 | 1521 | 1523 | 1369 | 1533 | 0 | 0 | 0 | 1487 | 1454 | 1518 | 1465 | 1542 |
113 | 2021-12 | 1654 | 1533 | 1513 | 1390 | 1511 | 0 | 0 | 0 | 1505 | 1442 | 1530 | 1453 | 1524 |
114 | 2021-13 | 1663 | 1547 | 1529 | 1381 | 1502 | 0 | 0 | 0 | 1491 | 1427 | 1540 | 1467 | 1509 |
115 | 2021-14 | 1643 | 1567 | 1544 | 1368 | 1487 | 0 | 0 | 0 | 1506 | 1440 | 1524 | 1484 | 1492 |
116 | 2021-15 | 1653 | 1581 | 1530 | 1388 | 1500 | 0 | 0 | 0 | 1520 | 1427 | 1514 | 1470 | 1472 |
df.to_csv("C:\\Users\\chris\\Desktop\\elo_over_time.csv", index=False)