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 numpy as np
import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sns
import pingouin
women_results = pd.read_csv('women_results.csv')
men_results = pd.read_csv('men_results.csv')
men_results.info()
women_results.info()
# Convert the date column to datetime objects
women_results['date'] = pd.to_datetime(women_results['date']).dt.date
men_results['date'] = pd.to_datetime(men_results['date']).dt.date

# Create date to filter DataFrames by
comparision_date = pd.to_datetime('2002-01-01').date()

# Filter both men and women results for FIFA World Cup tornament played since 2002-01-01
men_fifa_results = men_results[(men_results['tournament'] == 'FIFA World Cup') & (men_results['date'] >= comparision_date)]
women_fifa_results = women_results[(women_results['tournament'] == 'FIFA World Cup') & (women_results['date'] >= comparision_date)]
men_fifa_results.value_counts('tournament'), women_fifa_results.value_counts('tournament')
# Creating column for total goals scored
women_fifa_results['women_total_goals'] = women_fifa_results['home_score'] + women_fifa_results['away_score']
men_fifa_results['men_total_goals'] = men_fifa_results['home_score'] + men_fifa_results['away_score']

# Checking distribution for normality using histplot
sns.histplot(data=women_fifa_results, x='women_total_goals')
sns.histplot(data=men_fifa_results, x='men_total_goals')
plt.show()
# Run a Mann-Whitney U Test to calculate p_value
significance_level = 0.1
mwu_test = pingouin.mwu(x=women_fifa_results['women_total_goals'],
            y=men_fifa_results['men_total_goals'],
            alternative='greater')

# Compare p_value to significance level
comparision = np.array(mwu_test['p-val'])[0] == significance_level
print(comparision)
p_val = np.array(mwu_test['p-val'])[0]
result = "Reject"

result_dict ={'p_val':p_val, 'result':result}
result_dict