MH Projects

Formula 1 Data Analysis

Manuel Hinke - August 2021

As I work to master the skills of machine learning and data science with Kaggle's 30 Days of ML course and IBM's Data Science Professional Certificate, I decided to concurrently embark on a journey into the world of Formula 1 data to refine and apply the skills while I learn.

In order to do this I have decided to follow this outline:

  1. Load Data
  2. Interpret Data
  3. Clean Data
  4. Analyze Data
  5. Apply ML to Data

Load Data

First, we must import the libraries that will be used in this project.

In [2]:
import numpy as np
In [3]:
import pandas as pd
pd.set_option('display.max_rows', 130) 
In [5]:
import matplotlib.pyplot as plt
%matplotlib inline

To load our data,

In [6]:
def load_data(path):
    try:
        df = pd.read_csv(path)
        return df
    except IOError as e:
        print("There was an error reading data: " + str(e))
        return
In [27]:
dataFolder_path =  'F1Data/F1RaceDataFrom1950to2021'
raw_pathDrivers = dataFolder_path + '/drivers.csv'
In [28]:
df_rawDrivers = load_data(raw_pathDrivers)
df_rawDrivers
Out[28]:
driverId driverRef number code forename surname dob nationality url
0 1 hamilton 44 HAM Lewis Hamilton 1985-01-07 British http://en.wikipedia.org/wiki/Lewis_Hamilton
1 2 heidfeld \N HEI Nick Heidfeld 1977-05-10 German http://en.wikipedia.org/wiki/Nick_Heidfeld
2 3 rosberg 6 ROS Nico Rosberg 1985-06-27 German http://en.wikipedia.org/wiki/Nico_Rosberg
3 4 alonso 14 ALO Fernando Alonso 1981-07-29 Spanish http://en.wikipedia.org/wiki/Fernando_Alonso
4 5 kovalainen \N KOV Heikki Kovalainen 1981-10-19 Finnish http://en.wikipedia.org/wiki/Heikki_Kovalainen
... ... ... ... ... ... ... ... ... ...
848 850 pietro_fittipaldi 51 FIT Pietro Fittipaldi 1996-06-25 Brazilian http://en.wikipedia.org/wiki/Pietro_Fittipaldi
849 851 aitken 89 AIT Jack Aitken 1995-09-23 British http://en.wikipedia.org/wiki/Jack_Aitken
850 852 tsunoda 22 TSU Yuki Tsunoda 2000-05-11 Japanese http://en.wikipedia.org/wiki/Yuki_Tsunoda
851 853 mazepin 9 MAZ Nikita Mazepin 1999-03-02 Russian http://en.wikipedia.org/wiki/Nikita_Mazepin
852 854 mick_schumacher 47 MSC Mick Schumacher 1999-03-22 German http://en.wikipedia.org/wiki/Mick_Schumacher

853 rows × 9 columns

In [30]:
raw_pathRaces = dataFolder_path + '/races.csv'
df_rawRaces = load_data(raw_pathRaces)
df_rawRaces
Out[30]:
raceId year round circuitId name date time url
0 1 2009 1 1 Australian Grand Prix 2009-03-29 06:00:00 http://en.wikipedia.org/wiki/2009_Australian_G...
1 2 2009 2 2 Malaysian Grand Prix 2009-04-05 09:00:00 http://en.wikipedia.org/wiki/2009_Malaysian_Gr...
2 3 2009 3 17 Chinese Grand Prix 2009-04-19 07:00:00 http://en.wikipedia.org/wiki/2009_Chinese_Gran...
3 4 2009 4 3 Bahrain Grand Prix 2009-04-26 12:00:00 http://en.wikipedia.org/wiki/2009_Bahrain_Gran...
4 5 2009 5 4 Spanish Grand Prix 2009-05-10 12:00:00 http://en.wikipedia.org/wiki/2009_Spanish_Gran...
... ... ... ... ... ... ... ... ...
1053 1069 2021 18 69 United States Grand Prix 2021-10-24 19:00:00 http://en.wikipedia.org/wiki/2021_United_State...
1054 1070 2021 19 32 Mexico City Grand Prix 2021-10-31 19:00:00 http://en.wikipedia.org/wiki/2021_Mexican_Gran...
1055 1071 2021 20 18 Brazilian Grand Prix 2021-11-07 17:00:00 http://en.wikipedia.org/wiki/2021_Brazilian_Gr...
1056 1072 2021 22 77 Saudi Arabian Grand Prix 2021-12-05 16:00:00 http://en.wikipedia.org/wiki/2021_Saudi_Arabia...
1057 1073 2021 23 24 Abu Dhabi Grand Prix 2021-12-12 13:00:00 http://en.wikipedia.org/wiki/2021_Abu_Dhabi_Gr...

1058 rows × 8 columns

In [35]:
df_rawRaces21 = df_rawRaces.loc[df_rawRaces['year'] == 2021]
df_rawRaces21
Out[35]:
raceId year round circuitId name date time url
1035 1053 2021 2 21 Emilia Romagna Grand Prix 2021-04-18 13:00:00 http://en.wikipedia.org/wiki/2021_Emilia_Romag...
1036 1052 2021 1 3 Bahrain Grand Prix 2021-03-28 15:00:00 https://en.wikipedia.org/wiki/2021_Bahrain_Gra...
1037 1051 2021 21 1 Australian Grand Prix 2021-11-21 06:00:00 http://en.wikipedia.org/wiki/2021_Australian_G...
1038 1054 2021 3 75 Portuguese Grand Prix 2021-05-02 13:00:00 http://en.wikipedia.org/wiki/2021_Portuguese_G...
1039 1055 2021 4 4 Spanish Grand Prix 2021-05-09 13:00:00 http://en.wikipedia.org/wiki/2021_Spanish_Gran...
1040 1056 2021 5 6 Monaco Grand Prix 2021-05-23 13:00:00 http://en.wikipedia.org/wiki/2021_Monaco_Grand...
1041 1057 2021 6 73 Azerbaijan Grand Prix 2021-06-06 12:00:00 http://en.wikipedia.org/wiki/2021_Azerbaijan_G...
1042 1058 2021 7 7 Canadian Grand Prix 2021-06-13 18:00:00 http://en.wikipedia.org/wiki/2021_Canadian_Gra...
1043 1059 2021 8 34 French Grand Prix 2021-06-27 13:00:00 http://en.wikipedia.org/wiki/2021_French_Grand...
1044 1060 2021 9 70 Austrian Grand Prix 2021-07-04 13:00:00 http://en.wikipedia.org/wiki/2021_Austrian_Gra...
1045 1061 2021 10 9 British Grand Prix 2021-07-18 14:00:00 http://en.wikipedia.org/wiki/2021_British_Gran...
1046 1062 2021 11 11 Hungarian Grand Prix 2021-08-01 13:00:00 http://en.wikipedia.org/wiki/2021_Hungarian_Gr...
1047 1063 2021 12 13 Belgian Grand Prix 2021-08-29 13:00:00 http://en.wikipedia.org/wiki/2021_Belgian_Gran...
1048 1064 2021 13 39 Dutch Grand Prix 2021-09-05 13:00:00 http://en.wikipedia.org/wiki/2021_Dutch_Grand_...
1049 1065 2021 14 14 Italian Grand Prix 2021-09-12 13:00:00 http://en.wikipedia.org/wiki/2021_Italiian_Gra...
1050 1066 2021 15 71 Russian Grand Prix 2021-09-26 12:00:00 http://en.wikipedia.org/wiki/2021_Russian_Gran...
1051 1067 2021 16 15 Singapore Grand Prix 2021-10-03 12:00:00 http://en.wikipedia.org/wiki/2021_Singapore_Gr...
1052 1068 2021 17 22 Japanese Grand Prix 2021-10-10 05:00:00 http://en.wikipedia.org/wiki/2021_Japanese_Gra...
1053 1069 2021 18 69 United States Grand Prix 2021-10-24 19:00:00 http://en.wikipedia.org/wiki/2021_United_State...
1054 1070 2021 19 32 Mexico City Grand Prix 2021-10-31 19:00:00 http://en.wikipedia.org/wiki/2021_Mexican_Gran...
1055 1071 2021 20 18 Brazilian Grand Prix 2021-11-07 17:00:00 http://en.wikipedia.org/wiki/2021_Brazilian_Gr...
1056 1072 2021 22 77 Saudi Arabian Grand Prix 2021-12-05 16:00:00 http://en.wikipedia.org/wiki/2021_Saudi_Arabia...
1057 1073 2021 23 24 Abu Dhabi Grand Prix 2021-12-12 13:00:00 http://en.wikipedia.org/wiki/2021_Abu_Dhabi_Gr...
In [ ]: