You're working as a sports journalist at a major online sports media company, specializing in soccer analysis and reporting. You've been watching both men's and women's international soccer matches for a number of years, and your gut instinct tells you that more goals are scored in women's international football matches than men's. This would make an interesting investigative article that your subscribers are bound to love, but you'll need to perform a valid statistical hypothesis test to be sure!
While scoping this project, you acknowledge that the sport has changed a lot over the years, and performances likely vary a lot depending on the tournament, so you decide to limit the data used in the analysis to only official FIFA World Cup
matches (not including qualifiers) since 2002-01-01
.
You create two datasets containing the results of every official men's and women's international football match since the 19th century, which you scraped from a reliable online source. This data is stored in two CSV files: women_results.csv
and men_results.csv
.
The question you are trying to determine the answer to is:
Are more goals scored in women's international soccer matches than men's?
You assume a 10% significance level, and use the following null and alternative hypotheses:
# Start your code here!
import pandas as pd
import matplotlib.pyplot as plt
import pingouin
from scipy.stats import mannwhitneyu
Importing and exploring the Datasets
explore to find out, check for missing values, datatypes for categories
# importing the men's dataset
men_results = pd.read_csv('men_results.csv')
# check info on dataset
print(men_results.info())
# importing the women's dataset
women_results = pd.read_csv('women_results.csv')
# check info
print(women_results.info())
Transform date column to date_time object
Transform the date column for both datasets
# convert date column data type
men_results['date'] = pd.to_datetime(men_results['date'])
women_results['date'] = pd.to_datetime(women_results['date'])
# verify
print(men_results['date'].dtype)
print(women_results['date'].dtype)
# check for unique values in tournament column
print(list(men_results['tournament'].unique()))
# filter for fifa world cup games played after 2002
# filter for mens and womens fifa world cup games
mens_fifa_wc = men_results['tournament'] == 'FIFA World Cup'
womens_fifa_wc = women_results['tournament'] == 'FIFA World Cup'
# filter for games played after 2002-01-01
mens_2002 = men_results['date'] > '2002-01-01'
womens_2002 = women_results['date'] > '2002-01-01'
# Subsetting with the two filters
men_goals = men_results[mens_fifa_wc & mens_2002]
women_goals = women_results[womens_fifa_wc & womens_2002]
Hypothesis Testing
both interested in total scores we need groups so we create columns we need determining normality of the groups
# create columns for group and goals scored
men_goals['group']= 'men'
men_goals['goals_scored'] = men_goals['home_score'] + men_goals['away_score']
women_goals['group'] = 'women'
women_goals['goals_scored'] = women_goals['home_score'] + women_goals['away_score']
# checking distributions
men_goals['goals_scored'].hist()
plt.show()
plt.clf()
# checking distributions
women_goals['goals_scored'].hist()
plt.show()
plt.clf()
# Combine both datasets
men_women_goals = both = pd.concat([men_goals, women_goals], axis=0, ignore_index=True)
men_women_goals
# pivot table
men_women_goals_wide = men_women_goals.pivot(columns="group", values="goals_scored")
men_women_goals_wide