Skip to content

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:

: The mean number of goals scored in women's international soccer matches is the same as men's.

: The mean number of goals scored in women's international soccer matches is greater than men's.

# Start your code here!
import pandas as pd
from statsmodels.graphics.gofplots import qqplot
import matplotlib.pyplot as plt
import seaborn as sns
import numpy as np
import pingouin
from scipy.stats import mannwhitneyu,ttest_ind
from scipy.stats import t
alpha=0.1

Exploratory Data Analysis

First we start with removing useless column Unnamed : 0 cause the table is already indexed

womenResults=pd.read_csv('women_results.csv')
menResults=pd.read_csv('men_results.csv')
womenResults=womenResults.drop(['Unnamed: 0'],axis=1)
menResults=menResults.drop(['Unnamed: 0'],axis=1)
womenResults.columns

Then we start filtering to preserve only data since 2002

menResults['date']=pd.to_datetime(menResults['date'])
womenResults['date']=pd.to_datetime(womenResults['date'])
womenResults=womenResults[womenResults['date'].dt.year>=2002]
menResults=menResults[menResults['date'].dt.year>=2002]

Filtering categories to take only FIFA world Cup

menResults=menResults[menResults['tournament']=='FIFA World Cup']
womenResults=womenResults[womenResults['tournament']=='FIFA World Cup']

ADDING total score column to make the code manipulation easier

womenResults['total_score']=womenResults['home_score']+womenResults['away_score']
menResults['total_score']=menResults['home_score']+menResults['away_score']
womenMeanScore=womenResults['total_score'].mean()
menStdScore=menResults['total_score'].std()
womenStdScore=womenResults['total_score'].std()
menMeanScore=menResults['total_score'].mean()

We are going to investigate whether our data follow a normal dist or not

%matplotlib inline
plt.figure()
qqplot(menResults['total_score'],loc=menMeanScore,scale=menStdScore,line='45')
plt.title("Q-Q Plot: Total Goals in Men's FIFA World Cup Matches")
plt.figure()
sns.histplot(data=menResults,x='total_score',kde=True,color='blue')
plt.title("Distribution of Total Goals - Men's FIFA World Cup Matches (2002+)")
plt.xlabel("Goals Scored")
plt.show()
%matplotlib inline
plt.figure()
qqplot(womenResults['total_score'],loc=womenMeanScore,scale=womenStdScore,line='45')
plt.title("Q-Q Plot: Total Goals in Women's FIFA World Cup Matches")

plt.figure()
sns.histplot(data=womenResults,x='total_score',kde=True,color='pink')
plt.title("Distribution of Total Goals - Women's FIFA World Cup Matches (2002+)")
plt.xlabel("Goals Scored")
plt.show()

Since the qqplot and kde plot doesnt follow a bell curve we conclude that our data is not normally distibuted so we are going to use non paramteric test which is Wilcoxon-Mann-Whitney test cause we an unpaired t_test