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.

import numpy as np
import pandas as pd

# import t-test function from SciPy
from scipy.stats import ttest_ind
# read in the datasets, set date type for date column
mens_results = pd.read_csv('men_results.csv', parse_dates=['date'])
womens_results = pd.read_csv('women_results.csv', parse_dates=['date'])

womens_results.head(3)
# filter both to start from 2022
mens_post2022 = mens_results[mens_results['date'] >= pd.to_datetime("2022-01-01")]
womens_post2022 = womens_results[womens_results['date'] >= pd.to_datetime("2022-01-01")]

# filter both to inc. only world cup
mens_post2022 = mens_results[
    (mens_results['date'] >= pd.to_datetime("2002-01-01")) &
    (mens_results['tournament'] == "FIFA World Cup")]

womens_post2022 = womens_results[
    (womens_results['date'] >= pd.to_datetime("2002-01-01")) &
    (womens_results['tournament'] == "FIFA World Cup")]

womens_post2022.head()
# add a column to both df to include total goals scored per match
mens_post2022['match_goals'] = mens_post2022['home_score'] + mens_post2022['away_score']
womens_post2022['match_goals'] = womens_post2022['home_score'] + womens_post2022['away_score']

# create df that contains the key data from each dataset
mens_data = mens_post2022['match_goals'].tolist()
womens_data = womens_post2022['match_goals'].tolist()

print(womens_data)
# get the population for each (and also check list conversion was accurate)
print(len(womens_data), len(womens_post2022))
print(len(mens_data), len(mens_post2022))

Doing a lot of rapid searching / learning here...

# perform two-tailed Welch's t-test
t_stat, p_val = ttest_ind(womens_data, mens_data, equal_var=False)

# required output
result_dict = {
    "p_val": p_val,
    "result": "reject" if p_val < 0.10 else "fail to reject"
}

print(result_dict)