Name: Towards AI Legal Name: Towards AI, Inc. Description: Towards AI is the world's leading artificial intelligence (AI) and technology publication. Read by thought-leaders and decision-makers around the world. Phone Number: +1-650-246-9381 Email: pub@towardsai.net
228 Park Avenue South New York, NY 10003 United States
Website: Publisher: https://towardsai.net/#publisher Diversity Policy: https://towardsai.net/about Ethics Policy: https://towardsai.net/about Masthead: https://towardsai.net/about
Name: Towards AI Legal Name: Towards AI, Inc. Description: Towards AI is the world's leading artificial intelligence (AI) and technology publication. Founders: Roberto Iriondo, , Job Title: Co-founder and Advisor Works for: Towards AI, Inc. Follow Roberto: X, LinkedIn, GitHub, Google Scholar, Towards AI Profile, Medium, ML@CMU, FreeCodeCamp, Crunchbase, Bloomberg, Roberto Iriondo, Generative AI Lab, Generative AI Lab Denis Piffaretti, Job Title: Co-founder Works for: Towards AI, Inc. Louie Peters, Job Title: Co-founder Works for: Towards AI, Inc. Louis-François Bouchard, Job Title: Co-founder Works for: Towards AI, Inc. Cover:
Towards AI Cover
Logo:
Towards AI Logo
Areas Served: Worldwide Alternate Name: Towards AI, Inc. Alternate Name: Towards AI Co. Alternate Name: towards ai Alternate Name: towardsai Alternate Name: towards.ai Alternate Name: tai Alternate Name: toward ai Alternate Name: toward.ai Alternate Name: Towards AI, Inc. Alternate Name: towardsai.net Alternate Name: pub.towardsai.net
5 stars – based on 497 reviews

Frequently Used, Contextual References

TODO: Remember to copy unique IDs whenever it needs used. i.e., URL: 304b2e42315e

Resources

Take our 85+ lesson From Beginner to Advanced LLM Developer Certification: From choosing a project to deploying a working product this is the most comprehensive and practical LLM course out there!

Publication

Half Marathon Data Exploration and Visualization: using Python Plotly Library
Latest   Machine Learning

Half Marathon Data Exploration and Visualization: using Python Plotly Library

Last Updated on June 28, 2023 by Editorial Team

Author(s): David Cullen

Originally published on Towards AI.

London Landmarks Half Marathon 2023

In April of this year, I ran the London Landmarks Half Marathon for the first time. The race included 17,225 registered participants between the ages of 17–89 and managed to raise over £10 million for 450 charities (well-done everyone!).

Following the race, I was emailed helpful summary statistics, such as position in the race, average speed, and split times, including a link to the race data in.xlsx format.

In addition to the summary statistics already available, I thought it would be interesting to explore the data in a bit more detail, which led me to write this article, covering:

  • Data Extraction: download data and store it in Pandas DataFrame.
  • Data Preparation: data cleaning using NumPy and Pandas.
  • Data Overview: data overview, visualized using Plotly.
  • Data Distribution: kernel density estimation and empirical cumulative distribution function visualized using Plotly.
  • Average Speed Analysis: analysis of participant speed across a variety of chiptime splits, visualized using Plotly.

Each analysis in this article includes the relevant Python code to enable the reader to follow along programmatically.

Important Note: The majority of the visuals in this article are interactive — just follow the link in each respective title. For this, I have used Plotly Chart Studio: https://chart-studio.plotly.com. A tutorial on implementing interactive plots is outside the scope of this article. The reader will be able to replicate the visuals in this article directly from their interactive computing environment (i.e., Jupyter Notebook).

Photo by Mārtiņš Zemlickis on Unsplash

Dataset

The dataset [1] consists of 26 attributes, of which the following has been used in this article:

  • Chiptime: Finishing chiptime.
  • Category: Age group by gender.
  • Gender: Male or Female.
  • Avg speed: Runner km/hr average race speed.
  • Split — 5K — Cumulative time: Runner 5k time.
  • Split — 10K — Cumulative time: Runner 10k time.
  • Split — 15K — Cumulative time: Runner 15k time.
  • Split — 20K — Cumulative time: Runner 20k time.

I chose the above attributes, as I personally have found these data most interesting from a performance perspective.

Below details the process for data extraction.

Import Libraries:

We will first import the required libraries:

import requests # html requests
import numpy as np # data analysis
import pandas as pd # dataframe creation and analysis
from scipy import stats # central tendency anaysis
import dash # plots
import jupyter_dash # open plots in notebook
import plotly.express as px # plots
import plotly.figure_factory as ff # plots
import locale # comma separators in plot

Data Extraction:

We will now inspect the link html and find the relevant href. From here we extract the url to get the required data.

# url 
url = "https://mel-active-eventresults-webdynamiccontent.azurewebsites.net/data/downloadexcel?eventId=7037394564091167232&raceId=485022" # href url to dataset

# open the .xlsx file
with open('LLHM2023.xlsx', 'wb') as out_file:
response = requests.get(url, stream=True) # get data
content = response.content # get content
out_file.write(content) # write content

# dataframe
df = pd.read_excel('LLHM2023.xlsx').fillna(0) # create dataframe and fill na with 0
df1 = (df[['Chiptime','Split - 5K - Cumulative time','Split - 10K - Cumulative time','Split - 15K - Cumulative time','Split - 20K - Cumulative time','Gender','Avg speed','Category']])# create dataframe for analysis, selecting specific attributes.
df1.head() # inspect first 5 rows of the data

By running the above code, the data should now have been successfully stored in a DataFrame (df1) for cleansing.

Data Preparation:

We will now clean df1 to make it a bit more workable:

Datetime columns:

  • Convert time objects to second integers for later analysis.
  • Remove data that does not indicate Chiptime, to include recorded completion times only.

Category Column:

  • Convert Category elements to a sortable format for later analysis (i.e. remove gender prefix).

Gender Column:

  • Convert Gender elements to a readable format (from m and f to Male and Female).
  • Remove entries that do not specify the participant’s gender.

Average Speed Column:

  • Round the average speed for each participant to 2 decimal places.

General Column Renaming:

  • Rename columns to a clearer format.

The following function has been used to complete the above:

def clean_dataset(data):

# format time related columns
data['Chiptime Seconds'] = pd.TimedeltaIndex(data['Chiptime'].astype("str")).total_seconds().astype(int) # create seconds column
data = data[data['Chiptime Seconds'] > 0] # remove 0 value rows to only show registered completed particpants
data.loc[:, 'Split - 20K - Cumulative time'] = pd.TimedeltaIndex(data['Split - 20K - Cumulative time'].astype("str")).total_seconds().astype(int) # convert to seconds
data.loc[:, 'Split - 10K - Cumulative time'] = pd.TimedeltaIndex(data['Split - 10K - Cumulative time'].astype("str")).total_seconds().astype(int)# convert to seconds
data.loc[:, 'Split - 15K - Cumulative time'] = pd.TimedeltaIndex(data['Split - 15K - Cumulative time'].astype("str")).total_seconds().astype(int) # convert to seconds
data.loc[:, 'Split - 5K - Cumulative time'] = pd.TimedeltaIndex(data['Split - 5K - Cumulative time'].astype("str")).total_seconds().astype(int) # convert to seconds

# format 'Category' column
data['Category'] = data['Category'].str.slice(1)# slice first character (M/F), to enable category sorting of age category.
data.sort_values(by='Category', inplace=True) # category sorting
data['Category'].replace({'BC': 'Unknown'}, inplace=True) # preprocess
data = data[data['Category'] != 'Unknown'] # drop Unknown

# format "Gender" column
data["Gender"].replace(to_replace = "m",value="Male", inplace = True) # replace elemments in Gender column
data["Gender"].replace(to_replace = "f",value="Female", inplace = True) # replace elemments in Gender column
data["Gender"].replace(to_replace = 0,value="Not Specifed", inplace = True) # replace elemments in Gender column
data = data[data['Gender'] != 'Not Specifed'] # drop not specifed

# format 'Avg speed' column
data['Avg speed'] = data['Avg speed'].round(2) # round average speed

# general column renaming
data = data.rename(columns = {'Avg speed':'Avg speed km/hr','Category':'Age Category'}) # rename specified columns

return data
# clean and show the data
cleaned_df = clean_dataset(df1)
cleaned_df

Data Overview:

Now we can inspect the cleansed data.

Participants by Gender and Age Category:

Following data cleaning, 17,081 participant entries are usable. From this total, the majority of the participants were female, making up 58.6%. The remaining 41.4% of participants were male.

Table 1. Participants Overview (image created by the Author)
# calculate count and percentage of each 'Gender'
gender = cleaned_df.groupby(['Gender']).size().reset_index()
gender = gender.rename(columns={0: 'Count'})
gender['Percentage'] = gender.groupby(['Gender']).apply(lambda x: 100 * x / gender['Count'].sum()).round(1)

# add total row
total_row = gender[['Count']].sum().rename({0: 'Total'})
total_row['Percentage'] = (total_row['Count'] / total_row['Count'].sum() * 100).round(1)
gender = pd.concat([gender, total_row.to_frame().T])

# format percentage column elements
gender['Percentage'] = gender['Percentage'].astype(str) + '%'

# format count column elements
gender['Count'] = gender['Count'].map('{:,.0f}'.format)
gender = gender.reset_index()
gender = gender.drop(columns=['index'])
gender.loc[gender.index[-1], 'Gender'] = 'Total'

# show
gender

Count and Percentage of Participants by Age Category — Bar Chart:

Figure 1 shows the count and percentage of participants by age category across males and females.

25–29 is the most common age category, with 2,948 participants. This is then followed by age categories 30–34, totaling 2,434 participants, and 40–44, totaling 2,410 participants.

Less common age categories are 17–19, which sees 189 participants, and 65–69, which sees 153 participants. A substantial reduction in participants can also be seen from age 70 on.

Figure 1. Percentage of Participants by Age Category (image created by Author)
# create percentage by 'Age Category' dataframe
perc_age_group = cleaned_df.groupby(["Age Category"]).size().reset_index() # group by 'Age Category'
perc_age_group['Percentage'] = cleaned_df.groupby(["Age Category"]).size().groupby(level=0).apply(
lambda x: x / perc_age_group[0].sum()).values.round(4) *100 # add percentage column


# create a new column with concatenated values of 'Count' and 'Percentage' rounded to 2decimal place
perc_age_group.rename(columns = {0: 'Count'}, inplace = True)
perc_age_group['Count and Perc'] = perc_age_group['Count'].astype(str) + ' U+007C ' + perc_age_group['Percentage'].round(2).astype(str)+'%'

# set the locale for comma separators
locale.setlocale(locale.LC_ALL, '')

# create a new column with separate lines for 'Count' and 'Percentage'
perc_age_group['Text'] = (
perc_age_group['Count'].apply(lambda x: locale.format_string("%d", x, grouping=True)) + '<br>' +
perc_age_group['Percentage'].round(2).astype(str) + '%'
)
# plot
fig = px.bar(
perc_age_group,
x="Age Category",
y="Percentage",
text="Text",
template="simple_white"
)
# update traces
fig.update_traces(
textposition="outside",
textfont=dict(size=12)
)
# set plot colors and bar width
fig.update_traces(marker_color='grey')
fig.update_traces(width=0.90)

# set y-axis tick suffix as percentage
fig.update_layout(yaxis_ticksuffix='%')

# set y-axis range
fig.update_layout(yaxis_range=[0, 20])

# show
fig.show()

Percentage of Male and Female Participants by Age Category — Stacked Bar Chart:

Figure 2 shows that female participants represent the majority in most age categories.

Figure 2. Percentage of Male and Female Participants by Age Category (image created by the Author)
# percentage of 'Male' and 'Female' participants by 'Age Category':
perc_by_gender_and_age=cleaned_df.groupby(["Age Category","Gender"]).size().reset_index() # group
perc_by_gender_and_age['Percentage'] = cleaned_df.groupby(["Age Category","Gender"]).size().groupby(level=0).apply(lambda
x:100 * x/float(x.sum())).values.round(0) # add percentage of 'Gender'

# plot
fig=px.bar(perc_by_gender_and_age, x='Age Category', y='Percentage',color='Gender',text='Percentage',template="simple_white",text_auto=True)

# update layout
fig.update_layout(yaxis_ticksuffix = "%")

# update traces
fig.update_traces (textfont=dict(size=10,color='white'))
# show
fig.show()

Data Distribution:

Chiptime Kernel Density Estimation:

We will now perform Kernel Density Estimation (KDE) on the chiptime for all participants to estimate the probability density function. This will give us a good indication of the distribution of the data.

As shown, the distribution is right-skewed. The mode (most common value) and median (central value) are less than the mean (average). This is a characteristic of a right-skewed distribution due to the large spread in the right tail, representing slower half marathon chiptimes.

Inspection of the mean indicates an average completion time of 2 hours, 15 minutes. An increasing number of participants took longer to complete the race, as indicated by the elongated right tail, which pulls the average (mean) completion time upwards.

Following the examination of the median and mode, a different picture emerges. For example, 50% of all runners ran the race in 2 hours, 10 minutes, or less (median), and the most frequent participation completion time was 1 hour, 57 minutes (mode).

Figure 3. Chiptime Kernel Density Estimation (image created by the Author)
# create dataframe for plot
hist_data = [cleaned_df['Chiptime Seconds']]
group_labels = ['Density'] # group
colors = ['#333F44'] # colour

# create distplot
fig = ff.create_distplot(hist_data, group_labels,colors=colors,curve_type='kde',show_hist=False,show_curve = True) # kde plot

# calculate the mean, mode and median based on 'Chiptime' seconds
mean_chiptime = np.mean(cleaned_df['Chiptime Seconds'])
mode_chiptime = stats.mode(cleaned_df['Chiptime Seconds'])
median_chiptime = np.median(cleaned_df['Chiptime Seconds'])

# mean, mode and median as datetime object
mean_chiptime_text = pd.to_datetime(mean_chiptime, unit='s').strftime('%H:%M:%S')
mode_chiptime_text = pd.to_datetime(mode_chiptime[0].item(), unit='s').strftime('%H:%M:%S')
median_chiptime_text = pd.to_datetime(median_chiptime, unit='s').strftime('%H:%M:%S')

# add a vertical line for the mean, mode and median on plot
fig.add_vline(x=mean_chiptime, line_color='red', line_dash='dot',annotation_text= (f'Mean:{mean_chiptime_text}'),annotation_font=dict(color='red'))
fig.add_vline(x=mode_chiptime[0].item(), line_color='blue', line_dash='dot', annotation_text= (f'Mode:{mode_chiptime_text}'),annotation_position="top left",annotation_font=dict(color='blue'))
fig.add_vline(x=median_chiptime, line_color='yellow', line_dash='dot', annotation_text= (f'Median:{median_chiptime_text}'),annotation_position="bottom right",annotation_font=dict(color='yellow'))

# add datetime to x axis
fig.update_xaxes(
title='Chiptime',
showline=True,
tickvals=list(range(0, int(cleaned_df['Chiptime Seconds'].max()) + 5, 800)),
ticktext=pd.to_datetime(list(range(0, int(cleaned_df['Chiptime Seconds'].max()) + 5, 800)), unit='s').strftime('%H:%M:%S'),
tickangle=45
)

# update density trace attributes
density_trace = fig['data'][0]
density_trace['fill'] = 'tozeroy'
density_trace['line']['width'] = 2
density_trace['line']['color'] = 'black'

# update x-axis ticks with datetime labels
fig.update_xaxes(
title='Chiptime',
showline=True,
tickvals=list(range(0, int(cleaned_df['Chiptime Seconds'].max()) + 5, 800)),
ticktext=pd.to_datetime(list(range(0, int(cleaned_df['Chiptime Seconds'].max()) + 5, 800)), unit='s').strftime('%H:%M:%S'),
tickangle=45
)
# update layout for gridlines
fig.update_layout(
yaxis=dict(showgrid=True, gridcolor='lightgrey'),
xaxis=dict(showgrid=True, gridcolor='lightgrey')
)
# update background colors
fig.update_layout(
plot_bgcolor='white',
paper_bgcolor='white'
)
# show
fig.show()

Empirical Cumulative Distribution Function (ECDF) — Chiptime and Gender:

Next, we will plot the ECDF by gender. As shown in Figure 4, there is a higher probability for males to complete the half marathon faster than females. For example, approximately 80% of all males and approximately 50% of all females completed the race in under 2 hours and 20 minutes.

Figure 4. Empirical Cumulative Distribution Function based on Chiptime (image created by the Author)
# create dataframe 
ecdf = cleaned_df.loc[:,['Gender','Chiptime Seconds','Chiptime']]
ecdf.rename(columns = {'Chiptime Seconds': 'LLHM23 Chiptime'}, inplace = True)

# plot ecdf
fig = px.ecdf(ecdf, x="LLHM23 Chiptime", color="Gender", markers=True, lines=False, marginal="histogram",template="simple_white")

# update x-axis ticks with datetime ticks
fig.update_xaxes(
showline=True,
tickvals=list(range(0, int(cleaned_df['Chiptime Seconds'].max()) + 10, 400)),
ticktext=pd.to_datetime(list(range(0, int(cleaned_df['Chiptime Seconds'].max()) + 10, 400)), unit='s').strftime('%H:%M:%S'),
tickangle=45
)

# show gridline and space ticks
fig.update_layout(
xaxis = dict(showgrid = True),
yaxis = dict(showgrid = True),
)

# update axes title
fig.update_yaxes(title_text='Probability',row=1, col=1)
fig.update_xaxes(title_text='Chiptime',row=1, col=1)

# show
fig.show()

Participant Average Race Speed and Age Category — Box Plot:

Let’s now explore the central tendency, spread, and outliers based on average participant race speed (y-axis) and age category (x-axis).

As shown in Figure 5, the 1st and 3rd interquartile ranges (50% of the participants for each age category) generally look to be slowly declining in participant average race speed with age category.

The upper box (75th Percentile) in the age category 30–34 is the fastest, when compared to other age category upper boxes. The presence of the outlier in this category, represented by the race winner, further emphasizes the age category's high performance. The fastest median belongs to the age category 25–29, with a median average race speed of 10.01 km/hr. Both of these findings are particularly interesting, considering the view that runners tend to peak between the ages of 26 and 35 [2].

Up to age categories 70–74, a number of participants can be seen to fall outside of the upper (Quartile 3+1.5 * Interquartile Range) whiskers. These are outliers, so don’t feel bad if you can’t/couldn’t average these speeds for your age category over the entire 21km!

Important Note: for the later age categories (80–84 and 85–89), there are no whiskers or outliers, which is expected due to the limited sample size (as detailed earlier in this post).

Figure 5. Box Plot — Age Category and Average Speed (image created by the Author)
# create box plot
fig = px.box(cleaned_df, x="Age Category", y="Avg speed km/hr",template="simple_white",color_discrete_sequence=['#333F44'])

# update axis
fig.update_layout(yaxis_ticksuffix = 'km/hr')

# show boxplot
fig.show()

Average Speed Analysis:

Average Speed by Gender — Bar Chart:

We will now show the average race speed by gender.

Across both genders, the average race speed slowly declines per age category. This slow decline is a great metric to see. From a performance perspective, this is a testament to what the human body is capable of!

Figure 6. Average Speed by Gender (image created by the Author)

# group data by 'Age' and 'Gender' - calculate the mean
speed_data = cleaned_df.groupby(by=["Age Category", "Gender"]).mean().round(2).reset_index()

# create plot
fig = px.bar(
speed_data,
x='Age Category',
y='Avg speed km/hr',
color='Gender',
facet_row='Gender',
text_auto=True,
barmode='group',
template="simple_white"
)
# update layout
fig.update_layout(
bargap=1,
uniformtext_minsize=8,
height = 800
)

#update ticks
fig.update_layout(yaxis_ticksuffix = 'km/hr')
fig.update_layout(yaxis2_ticksuffix = 'km/hr')

# update trace
fig.update_traces(width=0.8)
fig.update_traces(textfont=dict(size=10, color='white'))

# show
fig.show()

Change in Average Split Speed:

We now show the average percentage change between the each 5k interval (4 splits):

  • Split 1: 0–5k Average Speed (km/hr).
  • Split 2 : 5k — 10k Average Speed (km/hr).
  • Split 3: 10k — 15k Average Speed (km/hr).
  • Split 4: 15k — 20k Average Speed (km/hr).

First, we create a DataFrame with the average speeds (km/hr) for each of the above split times.

We then perform a quantile cut, to bin data based on chiptime seconds across 4 discrete intervals. The 1st interval (Bin 1) approximately represents the fastest 25% runners and the 4th interval (Bin 4) approximately represents 25% of the slower runners.

— -Bin 1 — -Bin 2 — — — Bin 3 — — Bin 4

U+007C<- c.25% ->U+007C<- c.25% ->U+007C<- c.25% ->U+007C<- c.25% ->U+007C

As shown in Table 2, the faster runners (Bin 1), the more consistent their average speed is across 5k,10k,15k and 20k splits. This deteriorates as we move up the quantiles (Bins 2,3 and 4).

Table 2. Average Split Speed (km/hr) and Percentage Change in Average Speed across Splits — by Bin (image created by the Author)
# create average speed dataframe 
average_speed = cleaned_df.loc[(cleaned_df['Split - 20K - Cumulative time'] > 0)&(cleaned_df['Split - 15K - Cumulative time'] > 0) & (cleaned_df['Split - 10K - Cumulative time'] > 0) & (cleaned_df['Split - 5K - Cumulative time'] > 0)].copy()

# calculate average speed for each cumulative split time
average_speed['split_1_avg_km/hr'] = average_speed['Split - 5K - Cumulative time'].apply(lambda x:5/(x/3600)).round(2)
average_speed['split_2_avg_km/hr'] = average_speed['Split - 10K - Cumulative time'].apply(lambda x:10/(x/3600)).round(2)
average_speed['split_3_avg_km/hr'] = average_speed['Split - 15K - Cumulative time'].apply(lambda x:15/(x/3600)).round(2)
average_speed['split_4_avg_km/hr'] = average_speed['Split - 20K - Cumulative time'].apply(lambda x:20/(x/3600)).round(2)

# calculate the average percentage change from 5k to 20k
average_speed[['five_k_avg_km_perc', 'ten_k_avg_km_perc', 'fifthteen_k_avg_km_perc','twenty_k_avg_km_perc']] = average_speed[['split_1_avg_km/hr', 'split_2_avg_km/hr', 'split_3_avg_km/hr','split_4_avg_km/hr']].pct_change(axis=1)*100

# find the mean percentage change for each runner
average_speed['Average Percentage Change'] = average_speed[['ten_k_avg_km_perc', 'fifthteen_k_avg_km_perc','twenty_k_avg_km_perc',]].mean(axis=1).round(3)

# create quantile cuts - 4 quantiles to represent U+007C<- 25% ->U+007C<- 25% ->U+007C<- 25% ->U+007C<- 25% ->U+007C
labels = 'Bin 1', 'Bin 2','Bin 3','Bin 4'
average_speed['Bin'] = pd.qcut(average_speed['Chiptime Seconds'], len(labels), labels=labels)

# quantile cut
quantile_df = average_speed.groupby(['Bin']).mean().round(3).reset_index()
qcut_t1 = quantile_df[['Bin','split_1_avg_km/hr','split_2_avg_km/hr','split_3_avg_km/hr','split_4_avg_km/hr','Average Percentage Change']]
qcut_t1 = qcut_t1.round(2)
qcut_t1['Average Percentage Change'] = qcut_t1['Average Percentage Change'].apply( lambda x : str(x) + '%')

# show
qcut_t1

Average Race Speed versus Change in Average Speed between Splits 1 and 4 — Scatter Plot:

A visual representation of the average speed change between split 1 and split 4 (x axis), compared to the overall average race speed (y axis) for each participant, has been provided in Figure 7. This visual shows that the slower runners display a slower split 4 average speed when compared to split 1 average speed, across both genders. This means they generally slow down as the race progresses, which is also evident in Table 2 at the quantile level.

Fig 7. Participant Average Race Speed (Ave Speed km/hr) versus Change in Participant Average Speed between Splits 1 and 4
# split 1 and 4 speed difference 
average_speed ['split_1_to_split_4_change_in_avg_km/hr'] = average_speed ['split_4_avg_km/hr'] - average_speed ['split_1_avg_km/hr']

# plot
fig = px.scatter(average_speed, y='Avg speed km/hr', x ='split_1_to_split_4_change_in_avg_km/hr', color='Gender', facet_col='Gender', opacity=0.4,template="simple_white")

# update layout
fig.update_layout(xaxis_ticksuffix = 'km/hr')
fig.update_layout(xaxis2_ticksuffix = 'km/hr')
fig.update_layout(yaxis_ticksuffix = 'km/hr')
fig.update_layout(yaxis2_ticksuffix = 'km/hr')
fig.update_layout(
yaxis=dict(showgrid=True, gridcolor='lightgrey'),
xaxis=dict(showgrid=True, gridcolor='lightgrey')
)
fig.update_layout(
yaxis2=dict(showgrid=True, gridcolor='lightgrey'),
xaxis2=dict(showgrid=True, gridcolor='lightgrey')

)
# update x-axes
fig.update_xaxes(
title='Average Speed between Splits 1 and 4')

#show
fig.show()

Note: The analysis completed in Table 2 and Fig 7 required additional cleansing to only include recorded split times. The total recorded usable entries for these analyses are as follows:

Table 3 — Usable Entries for Percentage Change in Average Speed Analysis
# create count column
gender2 = average_speed.groupby('Gender').size().reset_index(name='Count')

# create percentage column
gender2['Percentage'] = (gender2['Count'] / gender2['Count'].sum() * 100).round(1)

# add total row
total_row2 = gender2[['Count']].sum().rename({0: 'Total'})
total_row2['Percentage'] = (total_row2['Count'] / total_row2['Count'].sum() * 100).round(1)
gender2 = pd.concat([gender2, total_row2.to_frame().T])

# format percentage column elements
gender2['Percentage'] = gender2['Percentage'].astype(str) + '%'

# format Count column elements
gender2['Count'] = gender2['Count'].map('{:,.0f}'.format)
gender2 = gender2.reset_index()
gender2 = gender2.drop(columns=['index'])
gender2.loc[gender2.index[-1], 'Gender'] = 'Total'

# show
gender2

Now it’s your time to run!

I hope you have enjoyed reading this article, and even better, I hope it has motivated you to run!

References

[1] https://results.sporthive.com/events/7037394564091167232

[2]https://www.runnersworld.com/uk/training/a774272/rules-of-running-runners-at-their-peak/#

Join thousands of data leaders on the AI newsletter. Join over 80,000 subscribers and keep up to date with the latest developments in AI. From research to projects and ideas. If you are building an AI startup, an AI-related product, or a service, we invite you to consider becoming a sponsor.

Published via Towards AI

Feedback ↓

Sign Up for the Course
`; } else { console.error('Element with id="subscribe" not found within the page with class "home".'); } } }); // Remove duplicate text from articles /* Backup: 09/11/24 function removeDuplicateText() { const elements = document.querySelectorAll('h1, h2, h3, h4, h5, strong'); // Select the desired elements const seenTexts = new Set(); // A set to keep track of seen texts const tagCounters = {}; // Object to track instances of each tag elements.forEach(el => { const tagName = el.tagName.toLowerCase(); // Get the tag name (e.g., 'h1', 'h2', etc.) // Initialize a counter for each tag if not already done if (!tagCounters[tagName]) { tagCounters[tagName] = 0; } // Only process the first 10 elements of each tag type if (tagCounters[tagName] >= 2) { return; // Skip if the number of elements exceeds 10 } const text = el.textContent.trim(); // Get the text content const words = text.split(/\s+/); // Split the text into words if (words.length >= 4) { // Ensure at least 4 words const significantPart = words.slice(0, 5).join(' '); // Get first 5 words for matching // Check if the text (not the tag) has been seen before if (seenTexts.has(significantPart)) { // console.log('Duplicate found, removing:', el); // Log duplicate el.remove(); // Remove duplicate element } else { seenTexts.add(significantPart); // Add the text to the set } } tagCounters[tagName]++; // Increment the counter for this tag }); } removeDuplicateText(); */ // Remove duplicate text from articles function removeDuplicateText() { const elements = document.querySelectorAll('h1, h2, h3, h4, h5, strong'); // Select the desired elements const seenTexts = new Set(); // A set to keep track of seen texts const tagCounters = {}; // Object to track instances of each tag // List of classes to be excluded const excludedClasses = ['medium-author', 'post-widget-title']; elements.forEach(el => { // Skip elements with any of the excluded classes if (excludedClasses.some(cls => el.classList.contains(cls))) { return; // Skip this element if it has any of the excluded classes } const tagName = el.tagName.toLowerCase(); // Get the tag name (e.g., 'h1', 'h2', etc.) // Initialize a counter for each tag if not already done if (!tagCounters[tagName]) { tagCounters[tagName] = 0; } // Only process the first 10 elements of each tag type if (tagCounters[tagName] >= 10) { return; // Skip if the number of elements exceeds 10 } const text = el.textContent.trim(); // Get the text content const words = text.split(/\s+/); // Split the text into words if (words.length >= 4) { // Ensure at least 4 words const significantPart = words.slice(0, 5).join(' '); // Get first 5 words for matching // Check if the text (not the tag) has been seen before if (seenTexts.has(significantPart)) { // console.log('Duplicate found, removing:', el); // Log duplicate el.remove(); // Remove duplicate element } else { seenTexts.add(significantPart); // Add the text to the set } } tagCounters[tagName]++; // Increment the counter for this tag }); } removeDuplicateText(); //Remove unnecessary text in blog excerpts document.querySelectorAll('.blog p').forEach(function(paragraph) { // Replace the unwanted text pattern for each paragraph paragraph.innerHTML = paragraph.innerHTML .replace(/Author\(s\): [\w\s]+ Originally published on Towards AI\.?/g, '') // Removes 'Author(s): XYZ Originally published on Towards AI' .replace(/This member-only story is on us\. Upgrade to access all of Medium\./g, ''); // Removes 'This member-only story...' }); //Load ionic icons and cache them if ('localStorage' in window && window['localStorage'] !== null) { const cssLink = 'https://code.ionicframework.com/ionicons/2.0.1/css/ionicons.min.css'; const storedCss = localStorage.getItem('ionicons'); if (storedCss) { loadCSS(storedCss); } else { fetch(cssLink).then(response => response.text()).then(css => { localStorage.setItem('ionicons', css); loadCSS(css); }); } } function loadCSS(css) { const style = document.createElement('style'); style.innerHTML = css; document.head.appendChild(style); } //Remove elements from imported content automatically function removeStrongFromHeadings() { const elements = document.querySelectorAll('h1, h2, h3, h4, h5, h6, span'); elements.forEach(el => { const strongTags = el.querySelectorAll('strong'); strongTags.forEach(strongTag => { while (strongTag.firstChild) { strongTag.parentNode.insertBefore(strongTag.firstChild, strongTag); } strongTag.remove(); }); }); } removeStrongFromHeadings(); "use strict"; window.onload = () => { /* //This is an object for each category of subjects and in that there are kewords and link to the keywods let keywordsAndLinks = { //you can add more categories and define their keywords and add a link ds: { keywords: [ //you can add more keywords here they are detected and replaced with achor tag automatically 'data science', 'Data science', 'Data Science', 'data Science', 'DATA SCIENCE', ], //we will replace the linktext with the keyword later on in the code //you can easily change links for each category here //(include class="ml-link" and linktext) link: 'linktext', }, ml: { keywords: [ //Add more keywords 'machine learning', 'Machine learning', 'Machine Learning', 'machine Learning', 'MACHINE LEARNING', ], //Change your article link (include class="ml-link" and linktext) link: 'linktext', }, ai: { keywords: [ 'artificial intelligence', 'Artificial intelligence', 'Artificial Intelligence', 'artificial Intelligence', 'ARTIFICIAL INTELLIGENCE', ], //Change your article link (include class="ml-link" and linktext) link: 'linktext', }, nl: { keywords: [ 'NLP', 'nlp', 'natural language processing', 'Natural Language Processing', 'NATURAL LANGUAGE PROCESSING', ], //Change your article link (include class="ml-link" and linktext) link: 'linktext', }, des: { keywords: [ 'data engineering services', 'Data Engineering Services', 'DATA ENGINEERING SERVICES', ], //Change your article link (include class="ml-link" and linktext) link: 'linktext', }, td: { keywords: [ 'training data', 'Training Data', 'training Data', 'TRAINING DATA', ], //Change your article link (include class="ml-link" and linktext) link: 'linktext', }, ias: { keywords: [ 'image annotation services', 'Image annotation services', 'image Annotation services', 'image annotation Services', 'Image Annotation Services', 'IMAGE ANNOTATION SERVICES', ], //Change your article link (include class="ml-link" and linktext) link: 'linktext', }, l: { keywords: [ 'labeling', 'labelling', ], //Change your article link (include class="ml-link" and linktext) link: 'linktext', }, pbp: { keywords: [ 'previous blog posts', 'previous blog post', 'latest', ], //Change your article link (include class="ml-link" and linktext) link: 'linktext', }, mlc: { keywords: [ 'machine learning course', 'machine learning class', ], //Change your article link (include class="ml-link" and linktext) link: 'linktext', }, }; //Articles to skip let articleIdsToSkip = ['post-2651', 'post-3414', 'post-3540']; //keyword with its related achortag is recieved here along with article id function searchAndReplace(keyword, anchorTag, articleId) { //selects the h3 h4 and p tags that are inside of the article let content = document.querySelector(`#${articleId} .entry-content`); //replaces the "linktext" in achor tag with the keyword that will be searched and replaced let newLink = anchorTag.replace('linktext', keyword); //regular expression to search keyword var re = new RegExp('(' + keyword + ')', 'g'); //this replaces the keywords in h3 h4 and p tags content with achor tag content.innerHTML = content.innerHTML.replace(re, newLink); } function articleFilter(keyword, anchorTag) { //gets all the articles var articles = document.querySelectorAll('article'); //if its zero or less then there are no articles if (articles.length > 0) { for (let x = 0; x < articles.length; x++) { //articles to skip is an array in which there are ids of articles which should not get effected //if the current article's id is also in that array then do not call search and replace with its data if (!articleIdsToSkip.includes(articles[x].id)) { //search and replace is called on articles which should get effected searchAndReplace(keyword, anchorTag, articles[x].id, key); } else { console.log( `Cannot replace the keywords in article with id ${articles[x].id}` ); } } } else { console.log('No articles found.'); } } let key; //not part of script, added for (key in keywordsAndLinks) { //key is the object in keywords and links object i.e ds, ml, ai for (let i = 0; i < keywordsAndLinks[key].keywords.length; i++) { //keywordsAndLinks[key].keywords is the array of keywords for key (ds, ml, ai) //keywordsAndLinks[key].keywords[i] is the keyword and keywordsAndLinks[key].link is the link //keyword and link is sent to searchreplace where it is then replaced using regular expression and replace function articleFilter( keywordsAndLinks[key].keywords[i], keywordsAndLinks[key].link ); } } function cleanLinks() { // (making smal functions is for DRY) this function gets the links and only keeps the first 2 and from the rest removes the anchor tag and replaces it with its text function removeLinks(links) { if (links.length > 1) { for (let i = 2; i < links.length; i++) { links[i].outerHTML = links[i].textContent; } } } //arrays which will contain all the achor tags found with the class (ds-link, ml-link, ailink) in each article inserted using search and replace let dslinks; let mllinks; let ailinks; let nllinks; let deslinks; let tdlinks; let iaslinks; let llinks; let pbplinks; let mlclinks; const content = document.querySelectorAll('article'); //all articles content.forEach((c) => { //to skip the articles with specific ids if (!articleIdsToSkip.includes(c.id)) { //getting all the anchor tags in each article one by one dslinks = document.querySelectorAll(`#${c.id} .entry-content a.ds-link`); mllinks = document.querySelectorAll(`#${c.id} .entry-content a.ml-link`); ailinks = document.querySelectorAll(`#${c.id} .entry-content a.ai-link`); nllinks = document.querySelectorAll(`#${c.id} .entry-content a.ntrl-link`); deslinks = document.querySelectorAll(`#${c.id} .entry-content a.des-link`); tdlinks = document.querySelectorAll(`#${c.id} .entry-content a.td-link`); iaslinks = document.querySelectorAll(`#${c.id} .entry-content a.ias-link`); mlclinks = document.querySelectorAll(`#${c.id} .entry-content a.mlc-link`); llinks = document.querySelectorAll(`#${c.id} .entry-content a.l-link`); pbplinks = document.querySelectorAll(`#${c.id} .entry-content a.pbp-link`); //sending the anchor tags list of each article one by one to remove extra anchor tags removeLinks(dslinks); removeLinks(mllinks); removeLinks(ailinks); removeLinks(nllinks); removeLinks(deslinks); removeLinks(tdlinks); removeLinks(iaslinks); removeLinks(mlclinks); removeLinks(llinks); removeLinks(pbplinks); } }); } //To remove extra achor tags of each category (ds, ml, ai) and only have 2 of each category per article cleanLinks(); */ //Recommended Articles var ctaLinks = [ /* ' ' + '

Subscribe to our AI newsletter!

' + */ '

Take our 85+ lesson From Beginner to Advanced LLM Developer Certification: From choosing a project to deploying a working product this is the most comprehensive and practical LLM course out there!

'+ '

Towards AI has published Building LLMs for Production—our 470+ page guide to mastering LLMs with practical projects and expert insights!

' + '
' + '' + '' + '

Note: Content contains the views of the contributing authors and not Towards AI.
Disclosure: This website may contain sponsored content and affiliate links.

' + 'Discover Your Dream AI Career at Towards AI Jobs' + '

Towards AI has built a jobs board tailored specifically to Machine Learning and Data Science Jobs and Skills. Our software searches for live AI jobs each hour, labels and categorises them and makes them easily searchable. Explore over 10,000 live jobs today with Towards AI Jobs!

' + '
' + '

🔥 Recommended Articles 🔥

' + 'Why Become an LLM Developer? Launching Towards AI’s New One-Stop Conversion Course'+ 'Testing Launchpad.sh: A Container-based GPU Cloud for Inference and Fine-tuning'+ 'The Top 13 AI-Powered CRM Platforms
' + 'Top 11 AI Call Center Software for 2024
' + 'Learn Prompting 101—Prompt Engineering Course
' + 'Explore Leading Cloud Providers for GPU-Powered LLM Training
' + 'Best AI Communities for Artificial Intelligence Enthusiasts
' + 'Best Workstations for Deep Learning
' + 'Best Laptops for Deep Learning
' + 'Best Machine Learning Books
' + 'Machine Learning Algorithms
' + 'Neural Networks Tutorial
' + 'Best Public Datasets for Machine Learning
' + 'Neural Network Types
' + 'NLP Tutorial
' + 'Best Data Science Books
' + 'Monte Carlo Simulation Tutorial
' + 'Recommender System Tutorial
' + 'Linear Algebra for Deep Learning Tutorial
' + 'Google Colab Introduction
' + 'Decision Trees in Machine Learning
' + 'Principal Component Analysis (PCA) Tutorial
' + 'Linear Regression from Zero to Hero
'+ '

', /* + '

Join thousands of data leaders on the AI newsletter. It’s free, we don’t spam, and we never share your email address. Keep up to date with the latest work in AI. From research to projects and ideas. If you are building an AI startup, an AI-related product, or a service, we invite you to consider becoming a sponsor.

',*/ ]; var replaceText = { '': '', '': '', '
': '
' + ctaLinks + '
', }; Object.keys(replaceText).forEach((txtorig) => { //txtorig is the key in replacetext object const txtnew = replaceText[txtorig]; //txtnew is the value of the key in replacetext object let entryFooter = document.querySelector('article .entry-footer'); if (document.querySelectorAll('.single-post').length > 0) { //console.log('Article found.'); const text = entryFooter.innerHTML; entryFooter.innerHTML = text.replace(txtorig, txtnew); } else { // console.log('Article not found.'); //removing comment 09/04/24 } }); var css = document.createElement('style'); css.type = 'text/css'; css.innerHTML = '.post-tags { display:none !important } .article-cta a { font-size: 18px; }'; document.body.appendChild(css); //Extra //This function adds some accessibility needs to the site. function addAlly() { // In this function JQuery is replaced with vanilla javascript functions const imgCont = document.querySelector('.uw-imgcont'); imgCont.setAttribute('aria-label', 'AI news, latest developments'); imgCont.title = 'AI news, latest developments'; imgCont.rel = 'noopener'; document.querySelector('.page-mobile-menu-logo a').title = 'Towards AI Home'; document.querySelector('a.social-link').rel = 'noopener'; document.querySelector('a.uw-text').rel = 'noopener'; document.querySelector('a.uw-w-branding').rel = 'noopener'; document.querySelector('.blog h2.heading').innerHTML = 'Publication'; const popupSearch = document.querySelector$('a.btn-open-popup-search'); popupSearch.setAttribute('role', 'button'); popupSearch.title = 'Search'; const searchClose = document.querySelector('a.popup-search-close'); searchClose.setAttribute('role', 'button'); searchClose.title = 'Close search page'; // document // .querySelector('a.btn-open-popup-search') // .setAttribute( // 'href', // 'https://medium.com/towards-artificial-intelligence/search' // ); } // Add external attributes to 302 sticky and editorial links function extLink() { // Sticky 302 links, this fuction opens the link we send to Medium on a new tab and adds a "noopener" rel to them var stickyLinks = document.querySelectorAll('.grid-item.sticky a'); for (var i = 0; i < stickyLinks.length; i++) { /* stickyLinks[i].setAttribute('target', '_blank'); stickyLinks[i].setAttribute('rel', 'noopener'); */ } // Editorial 302 links, same here var editLinks = document.querySelectorAll( '.grid-item.category-editorial a' ); for (var i = 0; i < editLinks.length; i++) { editLinks[i].setAttribute('target', '_blank'); editLinks[i].setAttribute('rel', 'noopener'); } } // Add current year to copyright notices document.getElementById( 'js-current-year' ).textContent = new Date().getFullYear(); // Call functions after page load extLink(); //addAlly(); setTimeout(function() { //addAlly(); //ideally we should only need to run it once ↑ }, 5000); }; function closeCookieDialog (){ document.getElementById("cookie-consent").style.display = "none"; return false; } setTimeout ( function () { closeCookieDialog(); }, 15000); console.log(`%c 🚀🚀🚀 ███ █████ ███████ █████████ ███████████ █████████████ ███████████████ ███████ ███████ ███████ ┌───────────────────────────────────────────────────────────────────┐ │ │ │ Towards AI is looking for contributors! │ │ Join us in creating awesome AI content. │ │ Let's build the future of AI together → │ │ https://towardsai.net/contribute │ │ │ └───────────────────────────────────────────────────────────────────┘ `, `background: ; color: #00adff; font-size: large`); //Remove latest category across site document.querySelectorAll('a[rel="category tag"]').forEach(function(el) { if (el.textContent.trim() === 'Latest') { // Remove the two consecutive spaces (  ) if (el.nextSibling && el.nextSibling.nodeValue.includes('\u00A0\u00A0')) { el.nextSibling.nodeValue = ''; // Remove the spaces } el.style.display = 'none'; // Hide the element } }); // Add cross-domain measurement, anonymize IPs 'use strict'; //var ga = gtag; ga('config', 'G-9D3HKKFV1Q', 'auto', { /*'allowLinker': true,*/ 'anonymize_ip': true/*, 'linker': { 'domains': [ 'medium.com/towards-artificial-intelligence', 'datasets.towardsai.net', 'rss.towardsai.net', 'feed.towardsai.net', 'contribute.towardsai.net', 'members.towardsai.net', 'pub.towardsai.net', 'news.towardsai.net' ] } */ }); ga('send', 'pageview'); -->