Skip to content

Soccer Through the Ages

This dataset contains information on international soccer games throughout the years. It includes results of soccer games and information about the players who scored the goals. The dataset contains data from 1872 up to 2023.

๐Ÿ’พ The data

  • data/results.csv - CSV with results of soccer games between 1872 and 2023
    • home_score - The score of the home team, excluding penalty shootouts
    • away_score - The score of the away team, excluding penalty shootouts
    • tournament - The name of the tournament
    • city - The name of the city where the game was played
    • country - The name of the country where the game was played
    • neutral - Whether the game was played at a neutral venue or not
  • data/shootouts.csv - CSV with results of penalty shootouts in the soccer games
    • winner - The team that won the penalty shootout
  • data/goalscorers.csv - CSV with information on goal scorers of some of the soccer games in the results CSV
    • team - The team that scored the goal
    • scorer - The player who scored the goal
    • minute - The minute in the game when the goal was scored
    • own_goal - Whether it was an own goal or not
    • penalty - Whether the goal was scored as a penalty or not

The following columns can be found in all datasets:

  • date - The date of the soccer game
  • home_team - The team that played at home
  • away_team - The team that played away

These shared columns fully identify the game that was played and can be used to join data between the different CSV files.

Source: GitHub

๐Ÿ“Š Some guiding questions and visualization to help you explore this data:

  1. Which are the 15 countries that have won the most games since 1960? Show them in a horizontal bar plot.
  2. How many goals are scored in total in each minute of the game? Show this in a bar plot, with the minutes on the x-axis. If you're up for the challenge, you could even create an animated Plotly plot that shows how the distribution has changed over the years.
  3. Which 10 players have scored the most hat-tricks?
  4. What is the proportion of games won by each team at home and away? What is the difference between the proportions?
  5. How many games have been won by the home team? And by the away team?

๐Ÿ’ผ Develop a case study for your portfolio

After exploring the data, you can create a comprehensive case study using this dataset. We have provided an example objective below, but feel free to come up with your own - the world is your oyster!

Example objective: The UEFA Euro 2024 tournament is approaching. Utilize the historical data to construct a predictive model that forecasts potential outcomes of the tournament based on the team draws. Since the draws are not known yet, you should be able to configure them as variables in your notebook.

import pandas as pd
import numpy as np
import datetime as dt
import matplotlib.pyplot as plt
import matplotlib.ticker as ticker
import matplotlib.patches as mpatches
import seaborn as sns

results = pd.read_csv("data/results.csv", parse_dates=['date'])
shootouts = pd.read_csv("data/shootouts.csv", parse_dates=['date'])
goalscorers = pd.read_csv("data/goalscorers.csv", parse_dates=['date'])
def football_info(df):
    temp = pd.DataFrame(index=df.columns)
    temp["Datatype"] = df.dtypes
    temp["Not null values"] = df.count()
    temp["Null values"] = df.isnull().sum()
    temp["Percentage of null values"] = (df.isnull().mean())*100
    temp["Unique count"] = df.nunique()
    return temp
football_info(results)
football_info(shootouts)
football_info(goalscorers)
# Dropping the null values of the columns 'minute' and 'scorer' of the DF 'goalscorers' 
goalscorers.dropna(axis=0, subset=['minute', 'scorer'], inplace=True)
# Merging the DataFrames 'results' and 'shootouts'
data = results.merge(shootouts, on=['date', 'home_team', 'away_team'], how='left')
# Renaming the 'winner' column for clarity
data.rename(columns={'winner' : 'shootout_winner'}, inplace=True)
x = data[data.duplicated()].shape[0]
print(f"Number of duplicate rows: {x}")
print(f"Shape: {data.shape}")

Which are the 15 countries that have won the most games since 1960?

def game_winner(home_score, away_score, home_team, away_team):
    if home_score > away_score:
        winner = home_team
    elif home_score < away_score:
        winner = away_team
    else:
        winner = 'Draw'
    return winner

winner_team = data.apply(lambda row: game_winner(row['home_score'], row['away_score'], row['home_team'], row['away_team']), axis=1)
data['game_winner'] = winner_team
since_1960 = data[data['date'].dt.year >= 1960]
since_1960

Excluding penalty shootouts

games_won = since_1960.game_winner.value_counts()
if 'Draw' in games_won:
    games_won = games_won.drop('Draw')
games_won = pd.DataFrame({'country': games_won.index, 'n_of_games_won': games_won.values})

sns.barplot(x='n_of_games_won', y='country', data=games_won.head(15), edgecolor='black', color='#ff7100')
plt.title('Top 15 countries by games won since 1960')
plt.xlabel('Number of games won')
plt.ylabel('Country')
sns.despine(bottom=True, left=True)
plt.show()
โ€Œ
โ€Œ
โ€Œ