<jupyter_start><jupyter_text>Exploring Status IDs and Class IDs  Set Up<jupyter_code># Import necessary data libraries.
import pandas as pd
import os 
import csv
import io
import requests
import numpy as np
import matplotlib.pyplot as plt
# Set up URLs.
circuits_url = 'https://raw.githubusercontent.com/georgetown-analytics/Formula1/main/data/circuits.csv'
constructor_results_url = 'https://raw.githubusercontent.com/georgetown-analytics/Formula1/main/data/constructor_results.csv'
constructor_standings_url = 'https://raw.githubusercontent.com/georgetown-analytics/Formula1/main/data/constructor_standings.csv'
constructors_url = 'https://raw.githubusercontent.com/georgetown-analytics/Formula1/main/data/constructors.csv'
driver_standings_url = 'https://raw.githubusercontent.com/georgetown-analytics/Formula1/main/data/driver_standings.csv'
drivers_url = 'https://raw.githubusercontent.com/georgetown-analytics/Formula1/main/data/drivers.csv'
lap_times_url = 'https://raw.githubusercontent.com/georgetown-analytics/Formula1/main/data/lap_times.csv'
pit_stop_url = 'https://raw.githubusercontent.com/georgetown-analytics/Formula1/main/data/pit_stops.csv'
qualifying_url = 'https://raw.githubusercontent.com/georgetown-analytics/Formula1/main/data/qualifying.csv'
races_url = 'https://raw.githubusercontent.com/georgetown-analytics/Formula1/main/data/races.csv'
results_url = 'https://raw.githubusercontent.com/georgetown-analytics/Formula1/main/data/results.csv'
seasons_url = 'https://raw.githubusercontent.com/georgetown-analytics/Formula1/main/data/seasons.csv'
status_url = 'https://raw.githubusercontent.com/georgetown-analytics/Formula1/main/data/status.csv'
# Set up dataframes.
circuits_df = pd.read_csv(circuits_url, sep = ',', encoding = 'latin-1')
constructor_results_df = pd.read_csv(constructor_results_url, sep = ',', engine = 'python')
constructor_standings_df = pd.read_csv(constructor_standings_url, sep = ',', engine = 'python')
constructors_df = pd.read_csv(constructor_standings_url, sep = ',', engine = 'python')
driver_standings_df = pd.read_csv(driver_standings_url, sep = ',', engine = 'python')
lap_times_df = pd.read_csv(lap_times_url, sep = ',', engine = 'python')
pit_stop_df = pd.read_csv(pit_stop_url, sep = ',', engine = 'python')
qualifying_df = pd.read_csv(constructor_standings_url, sep = ',', engine = 'python')
results_df = pd.read_csv(results_url, sep = ',', engine = 'python')
seasons_df = pd.read_csv(seasons_url, sep = ',', engine = 'python')
status_df = pd.read_csv(status_url, sep = ',', engine = 'python')
races_df = pd.read_csv(races_url, sep = ',', engine = 'c')
drivers_df = pd.read_csv(drivers_url, sep = ',', encoding = 'latin-1')
# See status_df.
status_df.head()<jupyter_output><empty_output><jupyter_text>Test Creation of Crash or No Crash Variable<jupyter_code>"""
Just trying to test the creation of a crash or no crash variable
(we can then expand this to include other classes).

Crash statuses: 3, 4, 20, 29, 104

source: https://www.dataquest.io/blog/tutorial-add-column-pandas-dataframe-based-on-if-else-condition/
"""

# Create the variable classID.
status_df['classID0'] = np.where(status_df.statusId == 3, 1, 0)
status_df['classID1'] = np.where(status_df.statusId == 4, 1, status_df.classID0)
status_df['classID2'] = np.where(status_df.statusId == 20, 1, status_df.classID1)
status_df['classID3'] = np.where(status_df.statusId == 29, 1, status_df.classID2)
status_df['classID'] = np.where(status_df.statusId == 104, 1, status_df.classID3)
# Dump any unnecessary variables.
status_df.drop("classID0", axis = 1, inplace = True)
status_df.drop("classID1", axis = 1, inplace = True)
status_df.drop("classID2", axis = 1, inplace = True)
status_df.drop("classID3", axis = 1, inplace = True)

status_df.head()
# Check variables in results_df.
results_df.head()
# Check variables in status_df.
status_df.head()<jupyter_output><empty_output><jupyter_text>Merge Datasets<jupyter_code># Merge results_df with status_df.
final_status = pd.merge(results_df, status_df, on = "statusId")
final_status.head()<jupyter_output><empty_output><jupyter_text>Explore Data<jupyter_code># Find the number of crashes in final_status.
final_status['classID'].sum()
# How many crashes and non-crashes do we have in our dataset?
final_status['classID'].value_counts()
# What is the breakdown of each status?
final_status['statusId'].value_counts()
# Plot the distribution of our statuses.
fig = plt.figure(figsize = (7,10))
ax = fig.add_subplot(212)
ax.hist(final_status['statusId'], bins = 50, range = (final_status['statusId'].min(), final_status['statusId'].max()))
plt.title('Status Distribution')
plt.xlabel('Status')
plt.ylabel('Count of Each Status')
plt.show()
wanted_status = [1, 11, 12, 13, 14, 15, 16, 17, 18, 19]
final_status_count = final_status[final_status['statusId'].isin(wanted_status)]
final_status_count.head()
final_status_count.value_counts("statusId")<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.14129554655870447, 'fraction_numerical': 0.01659919028340081, 'mean_word_length': 6.601538461538461, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 17, 'https://': 14, 'lorem ipsum': 0, 'www.': 1, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '4', 'dir': 'jupyter-structured-clean-dedup', 'id': '277341', 'license': 'MIT', 'n_tokens_mistral': 1825, 'n_tokens_neox': 1723, 'n_words': 314, 'path': '.ipynb_checkpoints/Exploring_StatusIDs_and_ClassIDs-checkpoint.ipynb', 'repo_name': 'georgetown-analytics/Formula1', 'size': '4940'}