Skip to content

Instantly share code, notes, and snippets.

@Xatpy
Created December 6, 2022 20:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Xatpy/38319d58f0df0c33d274872a7178d281 to your computer and use it in GitHub Desktop.
Save Xatpy/38319d58f0df0c33d274872a7178d281 to your computer and use it in GitHub Desktop.
World Cup 22 - Players by month of birth
import pandas as pd
import seaborn as sns
import matplotlib.pyplot as plt
import numpy as np
# Download the file "players_22.csv" from:
# https://drive.google.com/file/d/1EiNbO9zsoULzOcISLqGTkuxiSMM_zgVm/view?usp=share_link
df = pd.read_csv('players_22.csv', low_memory=False)
teams_worldcup = [
'Qatar', 'Brazil', 'Belgium', 'France', 'Argentina', 'England', 'Spain', 'Portugal',
'Mexico', 'Netherlands', 'Denmark', 'Germany', 'Uruguay', 'Switzerland', 'United States', 'Croatia',
'Senegal', 'Iran', 'Japan', 'Morocco', 'Serbia', 'Poland', 'South Korea', 'Tunisia',
'Cameroon', 'Canada', 'Ecuador', 'Saudi Arabia', 'Ghana', 'Wales', 'Costa Rica', 'Australia'
]
df = df[df['nationality_name'].isin(teams_worldcup)]
df = df[['dob', 'short_name', 'age', 'nationality_name', 'overall', 'club_name', 'player_positions',]]
df['dob'] = df['dob'].str.split('-', expand=True)[1]
df = df[df['dob'].astype(int) < 50]
df.dropna(inplace=True)
df.sort_values(by=['dob', 'short_name'], ascending=True, inplace=True)
print(df)
fig, ax = plt.subplots(figsize=(12, 5), tight_layout=True)
sns.set_style('darkgrid')
sns.histplot(df, x='dob', binwidth=1)
plt.show()
df.to_csv("out.csv")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment