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
import pandas as pd
import matplotlib.pyplot as plt
import pingouin
from scipy.stats import mannwhitneyu
# Load men's and women's datasets
men = pd.read_csv("men_results.csv")
women = pd.read_csv("women_results.csv")
men
men["date"] = pd.to_datetime(men["date"])
men_subset = men[(men["date"] > "2002-01-01") & (men["tournament"].isin(["FIFA World Cup"]))]
men_subset
men_subset["group"]="men"
men_subset

men_subset["goal_scored"]=men_subset["home_score"] + men_subset["away_score"]
men_subset
women["date"]=pd.to_datetime(women["date"])
women_subset = women[(women["date"] > "2002-01-01") & (women["tournament"].isin(["FIFA World Cup"]))]
women_subset["group"]="women"
women_subset["goal_scored"]=women_subset["home_score"] + women_subset["away_score"]
women_subset["goal_scored"].hist()
men_subset["goal_scored"].hist()
df = pd.concat([women_subset, men_subset], axis=0, ignore_index=True)
df
df_subset = df[["goal_scored", "group"]]
df_subset
import pandas as pd

# Sample data to define df
data = {
    'group': ['A', 'B', 'A', 'B'],
    'goal_scored': [1, 2, 3, 4]
}
df = pd.DataFrame(data)

# Assuming df_subset is supposed to be a subset of an existing DataFrame named df
df_subset = df[['group', 'goal_scored']]  # Create df_subset from df
df_pivot = df_subset.pivot(columns="group", values="goal_scored")

print(df_pivot)