Skip to content

Instantly share code, notes, and snippets.

@lmeulen
Last active August 23, 2022 15:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lmeulen/48e28f029e7b90d4571e45fc25077a6f to your computer and use it in GitHub Desktop.
Save lmeulen/48e28f029e7b90d4571e45fc25077a6f to your computer and use it in GitHub Desktop.
ergast_head2head_calc
year = 2022
driver1 = 'VER'
driver2 = 'PER'
race_results = stats.get_race_results(year)
dr = [ race_results[race_results.code == driver1]['driverId'].values[0],
race_results[race_results.code == driver2]['driverId'].values[0] ]
race_results['position'] = race_results['position'].replace(0, 30)
race=[0, 0, 10]
for rid in race_results.raceId.unique():
pos1 = race_results.loc[(race_results.raceId == rid) & \
(race_results.driverId == dr[0]), 'position'].values[0]
pos2 = race_results.loc[(race_results.raceId == rid) & \
(race_results.driverId == dr[1]), 'position'].values[0]
race[0] += 1 if pos1 < pos2 else 0
race[1] += 1 if pos2 < pos1 else 0
quali_results = stats.get_quali_results(year)
quali=[0, 0, 10]
for rid in quali_results.raceId.unique():
pos1 = quali_results.loc[(quali_results.raceId == rid) & \
(quali_results.driverId == dr[0]), 'position'].values[0]
pos2 = quali_results.loc[(quali_results.raceId == rid) & \
(quali_results.driverId == dr[1]), 'position'].values[0]
quali[0] += 1 if pos1 < pos2 else 0
quali[1] += 1 if pos2 < pos1 else 0
standings = stats.get_wdc_standing(year)
standings = standings[(standings['round'] == standings['round'].max())]
pnts = [ standings.loc[standings.driverId == dr[0], 'points'].values[0],
standings.loc[standings.driverId == dr[1], 'points'].values[0], 10]
wins = [ len(race_results.loc[(race_results['driverId'] == dr[0]) & \
(race_results['position'] == 1), 'position']),
len(race_results.loc[(race_results['driverId'] == dr[1]) & \
(race_results['position'] == 1), 'position']), 10]
podia = [ len(race_results.loc[(race_results['driverId'] == dr[0]) & \
(race_results['position'] <= 3), 'position']),
len(race_results.loc[(race_results['driverId'] == dr[1]) & \
(race_results['position'] <= 3), 'position']), 10]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment