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
#load data from men_csv 
df_men = pd.read_csv('men_results.csv')
df_men.head()
#load data from men_csv 
df_women = pd.read_csv('women_results.csv')
df_women.head()
#determine the data info
df_men.info()
#determine the data info
df_women.info()
#unique value of the category colum for men
df_men['tournament'].value_counts()
#unique value of the category colum for women
df_women['tournament'].value_counts()
# Convert the date column to datetime format
df_men['date'] = pd.to_datetime(df_men['date'])
df_women['date'] = pd.to_datetime(df_women['date'])

# Filter for FIFA World Cup matches after 2002-01-01
new_df_men = df_men[(df_men['tournament'] == 'FIFA World Cup') & (df_men['date'] > '2002-01-01')]
new_df_women = df_women[(df_women['tournament'] == 'FIFA World Cup') & (df_women['date'] > '2002-01-01')]
import matplotlib.pyplot as plt
import seaborn as sns
from scipy.stats import shapiro

# Calculate goals scored
new_df_men['goals_scored'] = new_df_men['home_score'] + new_df_men['away_score']
new_df_women['goals_scored'] = new_df_women['home_score'] + new_df_women['away_score']

# Plot histograms
plt.figure(figsize=(12, 6))
plt.subplot(1, 2, 1)
sns.histplot(new_df_men['goals_scored'], kde=True)
plt.title('Men\'s World Cup Goals')

plt.subplot(1, 2, 2)
sns.histplot(new_df_women['goals_scored'], kde=True)
plt.title('Women\'s World Cup Goals')
plt.show()
from scipy.stats import mannwhitneyu

# Perform Mann-Whitney U tes
results= mannwhitneyu(x=new_df_men['goals_scored'],y=new_df_women['goals_scored'],alternative='less')
p_val=results.pvalue

# Determine the result of the hypothesis test
alpha = 0.10
result = 'reject' if p_val < alpha else 'fail to reject'
# Store the result in a dictionary
result_dict = {"p_val": p_val, "result": result}
print(result_dict)