Analisi dati · Notebook in italiano
Olimpiadi: atleti e risultati dal 1896 al 2016
L’analisi completa di partecipazione, età, caratteristiche fisiche, sport e risultati, con i confronti dedicati all’Italia.
1896–2016 · raccolta storica
Edizione revisionata il . I risultati sono già calcolati: puoi leggere tutto qui e aprire il codice di ogni passaggio.
Il percorso comprende tutte le 136 celle del notebook inglese verificato, con spiegazioni in italiano e 71 risultati conservati. Codice, etichette dei grafici e tabelle mantengono la lingua originale. Gli approfondimenti metodologici seguono in appendice.
In questa analisi
Esplorazione dei dati dei Giochi olimpici

Copertina del rapporto ufficiale delle Olimpiadi estive del 1896.
Contenuto della raccolta
I dati sono stati estratti da www.sports-reference.com nel maggio 2018. Il file athlete_events.csv contiene 271.116 righe e 15 colonne: ogni riga rappresenta un atleta che partecipa a una specifica gara olimpica. Una persona può quindi comparire più volte.
| Colonna | Descrizione |
|---|---|
| ID | Identificativo univoco dell'atleta |
| Name | Nome dell'atleta |
| Sex | M o F, secondo la codifica della fonte |
| Age | Età, in anni interi |
| Height | Altezza in centimetri |
| Weight | Peso in chilogrammi |
| Team | Nome della squadra |
| NOC | Codice a tre lettere del comitato olimpico nazionale |
| Games | Anno e stagione dei Giochi |
| Year | Anno, come numero intero |
| Season | Estate o inverno |
| City | Città ospitante |
| Sport | Sport |
| Event | Gara |
| Medal | Oro, argento, bronzo oppure valore mancante |
Spero che questo lavoro sia utile. Se ti piace puoi sostenerlo con un voto su Kaggle. L'intenzione del progetto originale era continuare ad ampliarlo.
0. Preparazione dell'ambiente
Mostra il codice Python
import numpy as np
import pandas as pd
import seaborn as sns
import matplotlib as mpl
import matplotlib.pyplot as plt
print('Numpy Version : ', np.__version__)
print('Pandas Version : ', pd.__version__)
print('Matplotlib Version: ', mpl.__version__)
print('Seaborn Version : ', sns.__version__)
#seaborn options
sns.set_style('white')
#pandas options
pd.options.display.max_rows = 100
pd.options.display.max_columns = 100
Numpy Version : 1.16.3 Pandas Version : 0.23.4 Matplotlib Version: 3.0.3 Seaborn Version : 0.9.0
Funzioni di supporto
Mostra il codice Python
def missingData(data):
total = data.isnull().sum().sort_values(ascending = False)
percent = (data.isnull().sum()/data.isnull().count()*100).sort_values(ascending = False)
md = pd.concat([total, percent], axis=1, keys=['Total', 'Percent'])
md = md[md["Percent"] > 0]
plt.figure(figsize = (8, 4))
plt.xticks(rotation='90')
sns.barplot(md.index, md["Percent"],color="r",alpha=0.8)
plt.xlabel('Features', fontsize=15)
plt.ylabel('Percent of missing values', fontsize=15)
plt.title('Percent missing data by feature', fontsize=15)
return md
def valueCounts(dataset, features):
"""Display the features value counts """
for feature in features:
vc = dataset[feature].value_counts()
print(vc)
1. Importazione dei dati
Mostra il codice Python
data = pd.read_csv('../input/athlete_events.csv')
regions = pd.read_csv('../input/noc_regions.csv')
2. Prima esplorazione dei dati
Mostra il codice Python
data.sample(5)
| ID | Name | Sex | Age | Height | Weight | Team | NOC | Games | Year | Season | City | Sport | Event | Medal | |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 29576 | 15276 | Mario Brodmann | M | 25.0 | 176.0 | 80.0 | Switzerland | SUI | 1992 Winter | 1992 | Winter | Albertville | Ice Hockey | Ice Hockey Men's Ice Hockey | NaN |
| 67552 | 34525 | Hendrik Feldwehr | M | 25.0 | 192.0 | 90.0 | Germany | GER | 2012 Summer | 2012 | Summer | London | Swimming | Swimming Men's 100 metres Breaststroke | NaN |
| 269626 | 134921 | Octavian Petru Zidaru | M | 26.0 | 191.0 | 80.0 | Romania | ROU | 1980 Summer | 1980 | Summer | Moskva | Fencing | Fencing Men's epee, Team | NaN |
| 168089 | 84453 | Namjilyn Bayarsaikhan | M | 26.0 | 171.0 | 60.0 | Mongolia | MGL | 1992 Summer | 1992 | Summer | Barcelona | Boxing | Boxing Men's Lightweight | Bronze |
| 232211 | 116498 | Sun Wen | F | 23.0 | 162.0 | 60.0 | China | CHN | 1996 Summer | 1996 | Summer | Atlanta | Football | Football Women's Football | Silver |
Mostra il codice Python
data.info()
<class 'pandas.core.frame.DataFrame'> RangeIndex: 271116 entries, 0 to 271115 Data columns (total 15 columns): ID 271116 non-null int64 Name 271116 non-null object Sex 271116 non-null object Age 261642 non-null float64 Height 210945 non-null float64 Weight 208241 non-null float64 Team 271116 non-null object NOC 271116 non-null object Games 271116 non-null object Year 271116 non-null int64 Season 271116 non-null object City 271116 non-null object Sport 271116 non-null object Event 271116 non-null object Medal 39783 non-null object dtypes: float64(3), int64(2), object(10) memory usage: 31.0+ MB
Mostra il codice Python
data.describe()
| ID | Age | Height | Weight | Year | |
|---|---|---|---|---|---|
| count | 271116.000000 | 261642.000000 | 210945.000000 | 208241.000000 | 271116.000000 |
| mean | 68248.954396 | 25.556898 | 175.338970 | 70.702393 | 1978.378480 |
| std | 39022.286345 | 6.393561 | 10.518462 | 14.348020 | 29.877632 |
| min | 1.000000 | 10.000000 | 127.000000 | 25.000000 | 1896.000000 |
| 25% | 34643.000000 | 21.000000 | 168.000000 | 60.000000 | 1960.000000 |
| 50% | 68205.000000 | 24.000000 | 175.000000 | 70.000000 | 1988.000000 |
| 75% | 102097.250000 | 28.000000 | 183.000000 | 79.000000 | 2002.000000 |
| max | 135571.000000 | 97.000000 | 226.000000 | 214.000000 | 2016.000000 |
Mostra il codice Python
regions.head()
| NOC | region | notes | |
|---|---|---|---|
| 0 | AFG | Afghanistan | NaN |
| 1 | AHO | Curacao | Netherlands Antilles |
| 2 | ALB | Albania | NaN |
| 3 | ALG | Algeria | NaN |
| 4 | AND | Andorra | NaN |
Mostra il codice Python
regions.info()
<class 'pandas.core.frame.DataFrame'> RangeIndex: 230 entries, 0 to 229 Data columns (total 3 columns): NOC 230 non-null object region 227 non-null object notes 21 non-null object dtypes: object(3) memory usage: 5.5+ KB
3. Unione delle tabelle
Mostra il codice Python
allAthletes = pd.merge(data, regions, on='NOC', how='left')
Mostra il codice Python
allAthletes.sample(5)
| ID | Name | Sex | Age | Height | Weight | Team | NOC | Games | Year | Season | City | Sport | Event | Medal | region | notes | |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 202779 | 101856 | Tmas Rodrguez Ortz | M | 22.0 | 165.0 | 60.0 | Panama | PAN | 1984 Summer | 1984 | Summer | Los Angeles | Weightlifting | Weightlifting Men's Featherweight | NaN | Panama | NaN |
| 200635 | 100765 | Hubert Riesner | M | 22.0 | 183.0 | 63.0 | West Germany | FRG | 1968 Summer | 1968 | Summer | Mexico City | Athletics | Athletics Men's Marathon | NaN | Germany | NaN |
| 98227 | 49709 | James Benjamin Honeybone | M | 21.0 | 192.0 | 81.0 | Great Britain | GBR | 2012 Summer | 2012 | Summer | London | Fencing | Fencing Men's Sabre, Individual | NaN | UK | NaN |
| 76651 | 38907 | Arthur Stanley Garton | M | 23.0 | NaN | NaN | Leander Club-1 | GBR | 1912 Summer | 1912 | Summer | Stockholm | Rowing | Rowing Men's Coxed Eights | Gold | UK | NaN |
| 144056 | 72293 | ke Lundeberg | M | 23.0 | NaN | NaN | Sweden | SWE | 1912 Summer | 1912 | Summer | Stockholm | Shooting | Shooting Men's Trap | NaN | Sweden | NaN |
Mostra il codice Python
allAthletes.shape
(271116, 17)
4. Controllo dei dati mancanti
Mostra il codice Python
allAthletes.info()
<class 'pandas.core.frame.DataFrame'> Int64Index: 271116 entries, 0 to 271115 Data columns (total 17 columns): ID 271116 non-null int64 Name 271116 non-null object Sex 271116 non-null object Age 261642 non-null float64 Height 210945 non-null float64 Weight 208241 non-null float64 Team 271116 non-null object NOC 271116 non-null object Games 271116 non-null object Year 271116 non-null int64 Season 271116 non-null object City 271116 non-null object Sport 271116 non-null object Event 271116 non-null object Medal 39783 non-null object region 270746 non-null object notes 5039 non-null object dtypes: float64(3), int64(2), object(12) memory usage: 37.2+ MB
Uso una funzione per visualizzare le informazioni mancanti e capire quali variabili richiedono attenzione.
Mostra il codice Python
missingData(allAthletes)
| Total | Percent | |
|---|---|---|
| notes | 266077 | 98.141386 |
| Medal | 231333 | 85.326207 |
| Weight | 62875 | 23.191180 |
| Height | 60171 | 22.193821 |
| Age | 9474 | 3.494445 |
| region | 370 | 0.136473 |
I valori mancanti nella colonna Medal indicano partecipazioni senza medaglia nella gara considerata. Li sostituisco con l'etichetta No Medal.
Mostra il codice Python
allAthletes['Medal'].fillna('No Medal', inplace=True)
allAthletes.drop('notes', axis=1, inplace=True)
Mostra il codice Python
missingData(allAthletes)
| Total | Percent | |
|---|---|---|
| Weight | 62875 | 23.191180 |
| Height | 60171 | 22.193821 |
| Age | 9474 | 3.494445 |
| region | 370 | 0.136473 |
5. Esplorazione di tutti gli atleti olimpici
5.1 Qual è l'età media di un atleta olimpico?
Mostra il codice Python
allAthletes.describe()
| ID | Age | Height | Weight | Year | |
|---|---|---|---|---|---|
| count | 271116.000000 | 261642.000000 | 210945.000000 | 208241.000000 | 271116.000000 |
| mean | 68248.954396 | 25.556898 | 175.338970 | 70.702393 | 1978.378480 |
| std | 39022.286345 | 6.393561 | 10.518462 | 14.348020 | 29.877632 |
| min | 1.000000 | 10.000000 | 127.000000 | 25.000000 | 1896.000000 |
| 25% | 34643.000000 | 21.000000 | 168.000000 | 60.000000 | 1960.000000 |
| 50% | 68205.000000 | 24.000000 | 175.000000 | 70.000000 | 1988.000000 |
| 75% | 102097.250000 | 28.000000 | 183.000000 | 79.000000 | 2002.000000 |
| max | 135571.000000 | 97.000000 | 226.000000 | 214.000000 | 2016.000000 |
L'età media calcolata nel notebook originale è 25,55 anni; la mediana è 24 anni.
Queste statistiche sono calcolate sulle righe atleta-gara: chi prende parte a più gare pesa più volte nel risultato.
Mostra il codice Python
plt.figure(figsize=(20, 10))
sns.countplot(x= 'Age', hue='Sex', data=allAthletes )
plt.xticks(rotation = 90)
plt.legend(loc=1, fontsize='x-large')
plt.title('Distribution of olympic athletes by Age and Sex', fontsize = 20)
plt.show()
Mostra il codice Python
plt.figure(figsize=(20, 10))
sns.countplot(allAthletes['Age'], color='b')
plt.xticks(rotation = 90)
plt.title('Distribution of olympic athletes by Age', fontsize = 20)
plt.show()
Mostra il codice Python
allAthletes['ID'][allAthletes['Age'] > 60].count()
570
Chi è l'atleta più anziano?
Mostra il codice Python
allAthletes['Age'].max()
97.0
Mostra il codice Python
allAthletes[allAthletes['Age'] == 97].head()
| ID | Name | Sex | Age | Height | Weight | Team | NOC | Games | Year | Season | City | Sport | Event | Medal | region | |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 257054 | 128719 | John Quincy Adams Ward | M | 97.0 | NaN | NaN | United States | USA | 1928 Summer | 1928 | Summer | Amsterdam | Art Competitions | Art Competitions Mixed Sculpturing, Statues | No Medal | USA |
Nel lavoro originale ho segnalato un'anomalia: lo scultore John Quincy Adams Ward risulta nel dataset, ma è morto il 1° maggio 1910. Il caso richiede di distinguere partecipazioni sportive, competizioni artistiche e possibili presenze postume, prima di interpretarlo come record di longevità sportiva.
5.2 Quali sono altezza e peso mediani degli atleti?
Le colonne Weight e Height contengono valori mancanti. Riempirli con una media o una mediana generale nasconderebbe le differenze fisiche fra discipline. Per questa parte dell'analisi escludo le righe prive di quelle misure; le statistiche descrivono quindi soltanto le osservazioni disponibili.
Mostra il codice Python
allAthletesHW = allAthletes[(allAthletes['Height'].notnull()) & (allAthletes['Weight'].notnull())]
Mostra il codice Python
allAthletesHW.describe()
| ID | Age | Height | Weight | Year | |
|---|---|---|---|---|---|
| count | 206853.000000 | 206165.000000 | 206853.000000 | 206853.000000 | 206853.000000 |
| mean | 68582.647818 | 25.055509 | 175.359096 | 70.677365 | 1989.602848 |
| std | 39006.253624 | 5.483096 | 10.542004 | 14.330398 | 20.165420 |
| min | 1.000000 | 11.000000 | 127.000000 | 25.000000 | 1896.000000 |
| 25% | 35141.000000 | 21.000000 | 168.000000 | 60.000000 | 1976.000000 |
| 50% | 68595.000000 | 24.000000 | 175.000000 | 70.000000 | 1992.000000 |
| 75% | 102283.000000 | 28.000000 | 183.000000 | 79.000000 | 2006.000000 |
| max | 135571.000000 | 71.000000 | 226.000000 | 214.000000 | 2016.000000 |
- L'altezza media è 175,35 cm e il peso medio 70,67 kg.
- L'altezza mediana è 175 cm e il peso mediano 70 kg.
Prima rappresento la relazione con un diagramma a dispersione, poi uso i box plot per osservare l'evoluzione delle misure fra le edizioni.
Nota di traduzione: nel testo originale «mediano» al primo punto e «kg» per l'altezza al secondo erano refusi; qui sono esplicitate le grandezze corrette, senza modificare i calcoli.
Mostra il codice Python
plt.figure(figsize=(15, 15))
sns.scatterplot(x="Height", y="Weight", hue='Medal', data=allAthletesHW)
plt.title('Height VS Weight of Olympics Athletes', fontsize=20)
plt.show()
Chi è l'atleta con il peso maggiore?
Mostra il codice Python
allAthletesHW['Weight'].max()
214.0
Mostra il codice Python
allAthletesHW[allAthletesHW['Weight'] == 214].head()
| ID | Name | Sex | Age | Height | Weight | Team | NOC | Games | Year | Season | City | Sport | Event | Medal | region | |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 23155 | 12177 | Ricardo Blas, Jr. | M | 21.0 | 183.0 | 214.0 | Guam | GUM | 2008 Summer | 2008 | Summer | Beijing | Judo | Judo Men's Heavyweight | No Medal | Guam |
| 23156 | 12177 | Ricardo Blas, Jr. | M | 25.0 | 183.0 | 214.0 | Guam | GUM | 2012 Summer | 2012 | Summer | London | Judo | Judo Men's Heavyweight | No Medal | Guam |
Nel campione analizzato Ricardo Blas è l'atleta con il peso maggiore.
Chi è l'atleta più alto?
Mostra il codice Python
allAthletesHW['Height'].max()
226.0
Mostra il codice Python
allAthletesHW[allAthletesHW['Height'] == 226].head()
| ID | Name | Sex | Age | Height | Weight | Team | NOC | Games | Year | Season | City | Sport | Event | Medal | region | |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 265040 | 132627 | Yao Ming | M | 20.0 | 226.0 | 141.0 | China | CHN | 2000 Summer | 2000 | Summer | Sydney | Basketball | Basketball Men's Basketball | No Medal | China |
| 265041 | 132627 | Yao Ming | M | 23.0 | 226.0 | 141.0 | China | CHN | 2004 Summer | 2004 | Summer | Athina | Basketball | Basketball Men's Basketball | No Medal | China |
| 265042 | 132627 | Yao Ming | M | 27.0 | 226.0 | 141.0 | China | CHN | 2008 Summer | 2008 | Summer | Beijing | Basketball | Basketball Men's Basketball | No Medal | China |
Nel campione analizzato Yao Ming è l'atleta più alto.
Seguendo lo stesso ragionamento, studio come cambiano peso e altezza nelle diverse edizioni dei Giochi.
Mostra il codice Python
athletesMenHW = allAthletesHW[(allAthletesHW.Sex == 'M')]
athletesWomenHW = allAthletesHW[(allAthletesHW.Sex == 'F')]
summerMenHW = athletesMenHW[(athletesMenHW.Season == 'Summer')]
winterMenHW = athletesMenHW[(athletesMenHW.Season == 'Winter')]
summerWomenHW = athletesWomenHW[(athletesWomenHW.Season == 'Summer')]
winterWomenHW = athletesWomenHW[(athletesWomenHW.Season == 'Winter')]
print('Summer Male Athletes shape : ', summerMenHW.shape)
print('Winter Male Athletes shape : ', winterMenHW.shape)
print('Summer Female Athletes shape : ', summerWomenHW.shape)
print('Winter Female Athletes shape : ', winterWomenHW.shape)
Summer Male Athletes shape : (113962, 16) Winter Male Athletes shape : (26162, 16) Summer Female Athletes shape : (53399, 16) Winter Female Athletes shape : (13330, 16)
Variazione del peso
Mostra il codice Python
plt.figure(figsize=(30,18))
#1
plt.subplot(221)
sns.boxplot('Year', 'Weight', data=summerMenHW, palette='Oranges')
plt.title('Variation of Weight for Male Athletes in summer Olympics', fontsize=20)
#2
plt.subplot(222)
sns.boxplot('Year', 'Weight', data=summerWomenHW, palette='Oranges')
plt.title('Variation of Weight for Female Athletes in summer Olympics', fontsize=20)
#3
plt.subplot(223)
sns.boxplot('Year', 'Weight', data=winterMenHW, palette='Blues')
plt.title('Variation of Weight for Male Athletes in winter Olympics', fontsize=20)
#4
plt.subplot(224)
sns.boxplot('Year', 'Weight', data=winterWomenHW, palette='Blues')
plt.title('Variation of Weight for Female Athletes in winter Olympics', fontsize=20)
plt.show()
La linea dentro la scatola indica la mediana. I bordi della scatola corrispondono al primo e al terzo quartile. I baffi arrivano ai valori estremi entro la soglia del box plot; gli eventuali punti oltre i baffi sono mostrati separatamente come valori anomali.
Variazione dell'altezza
Mostra il codice Python
plt.figure(figsize=(30,18))
#1
plt.subplot(221)
sns.boxplot('Year', 'Height', data=summerMenHW, palette='Oranges')
plt.title('Variation of Height for Male Athletes in summer Olympics', fontsize=20)
#2
plt.subplot(222)
sns.boxplot('Year', 'Height', data=summerWomenHW, palette='Oranges')
plt.title('Variation of Height for Female Athletes in summer Olympics', fontsize=20)
#3
plt.subplot(223)
sns.boxplot('Year', 'Height', data=winterMenHW, palette='Blues')
plt.title('Variation of Height for Male Athletes in winter Olympics', fontsize=20)
#4
plt.subplot(224)
sns.boxplot('Year', 'Height', data=winterWomenHW, palette='Blues')
plt.title('Variation of Height for Female Athletes in winter Olympics', fontsize=20)
plt.show()
La linea dentro la scatola indica la mediana; i bordi sono il primo e il terzo quartile. I baffi mostrano l'estensione dei valori entro la soglia usata dal box plot, mentre gli eventuali valori anomali restano punti separati.
5.3 Come varia la partecipazione nel tempo?
Mostra il codice Python
athletesMen = allAthletes[(allAthletes.Sex == 'M')]
athletesWomen = allAthletes[(allAthletes.Sex == 'F')]
print('Male Athletes shape : ', athletesMen.shape)
print('Female Athletes shape : ', athletesWomen.shape)
Male Athletes shape : (196594, 16) Female Athletes shape : (74522, 16)
Mostra il codice Python
athletesMen.describe()
| ID | Age | Height | Weight | Year | |
|---|---|---|---|---|---|
| count | 196594.000000 | 187544.000000 | 143567.000000 | 141470.000000 | 196594.000000 |
| mean | 67601.598304 | 26.277562 | 178.858463 | 75.743677 | 1973.046064 |
| std | 39036.820069 | 6.474972 | 9.360318 | 13.211610 | 31.127867 |
| min | 1.000000 | 10.000000 | 127.000000 | 28.000000 | 1896.000000 |
| 25% | 33868.250000 | 22.000000 | 172.000000 | 67.000000 | 1952.000000 |
| 50% | 67271.500000 | 25.000000 | 179.000000 | 74.000000 | 1980.000000 |
| 75% | 101638.000000 | 29.000000 | 185.000000 | 83.000000 | 2000.000000 |
| max | 135571.000000 | 97.000000 | 226.000000 | 214.000000 | 2016.000000 |
Mostra il codice Python
athletesWomen.describe()
| ID | Age | Height | Weight | Year | |
|---|---|---|---|---|---|
| count | 74522.000000 | 74098.000000 | 67378.000000 | 66771.000000 | 74522.000000 |
| mean | 69956.722887 | 23.732881 | 167.839740 | 60.021252 | 1992.445748 |
| std | 38932.561177 | 5.795252 | 8.778528 | 10.212250 | 20.458993 |
| min | 5.000000 | 11.000000 | 127.000000 | 25.000000 | 1900.000000 |
| 25% | 36558.500000 | 20.000000 | 162.000000 | 54.000000 | 1984.000000 |
| 50% | 70128.000000 | 23.000000 | 168.000000 | 59.000000 | 1998.000000 |
| 75% | 103534.750000 | 27.000000 | 173.000000 | 65.000000 | 2008.000000 |
| max | 135568.000000 | 74.000000 | 213.000000 | 167.000000 | 2016.000000 |
Mostra il codice Python
summerMen = athletesMen[(athletesMen.Season == 'Summer')]
winterMen = athletesMen[(athletesMen.Season == 'Winter')]
summerWomen = athletesWomen[(athletesWomen.Season == 'Summer')]
winterWomen = athletesWomen[(athletesWomen.Season == 'Winter')]
print('Summer Male Athletes shape : ', summerMen.shape)
print('Winter Male Athletes shape : ', winterMen.shape)
print('Summer Female Athletes shape : ', summerWomen.shape)
print('Winter Female Athletes shape : ', winterWomen.shape)
Summer Male Athletes shape : (163109, 16) Winter Male Athletes shape : (33485, 16) Summer Female Athletes shape : (59443, 16) Winter Female Athletes shape : (15079, 16)
Mostra il codice Python
summerTicks = list(summerMen['Year'].unique())
summerTicks.sort()
winterTicks = list(winterMen['Year'].unique())
winterTicks.sort()
Mostra il codice Python
plt.figure(figsize=(30,18))
plt.subplot(221)
partSummerMen = summerMen.groupby('Year')['Sex'].value_counts()
partSummerMen.loc[:,'M'].plot(linewidth=4, color='b')
plt.xticks(summerTicks, rotation=90)
plt.title('Variation of Male Athletes in summer Olympics', fontsize=20)
plt.subplot(222)
partSummerWomen = summerWomen.groupby('Year')['Sex'].value_counts()
partSummerWomen.loc[:,'F'].plot(linewidth=4, color='r')
plt.xticks(summerTicks, rotation=90)
plt.title('Variation of Female Athletes in summer Olympics', fontsize=20)
plt.subplot(223)
partWinterMen = winterMen.groupby('Year')['Sex'].value_counts()
partWinterMen.loc[:,'M'].plot(linewidth=4, color='b')
plt.xticks(winterTicks, rotation=90)
plt.title('Variation of Male Athletes in winter Olympics', fontsize=20)
plt.subplot(224)
partWinterWomen = winterWomen.groupby('Year')['Sex'].value_counts()
partWinterWomen.loc[:,'F'].plot(linewidth=4, color='r')
plt.xticks(winterTicks, rotation=90)
plt.title('Variation of Female Athletes in winter Olympics', fontsize=20)
plt.show()
- Le guerre mondiali causarono la cancellazione dei Giochi del 1916, 1940 e 1944.
- Il testo originale richiama l'assegnazione dei Giochi del 1936 tramite voto dei membri del CIO per la città ospitante. Il voto si svolse nel 1931, negli ultimi anni della Repubblica di Weimar, due anni prima dell'ascesa al potere di Hitler e del partito nazista. I Giochi di Berlino sono ricordati anche per la staffetta della torcia.
- I primi Giochi olimpici invernali si svolsero nel 1924 a Chamonix, in Francia.
- Dal 1994 i Giochi invernali si tengono ogni quattro anni, a distanza di due anni dai Giochi estivi.
- Nel 1980 a Mosca e nel 1984 a Los Angeles si verificarono i boicottaggi contrapposti legati alla Guerra fredda.
- I Giochi intermedi del 1906 si svolsero ad Atene. All'epoca erano considerati olimpici e indicati dal CIO come i secondi Giochi olimpici internazionali di Atene. Le medaglie assegnate non sono però comprese nel conteggio olimpico ufficiale del CIO né nella collezione olimpica del museo di Losanna. Il richiamo storico del notebook proviene da Wikipedia.
6. Analisi delle medaglie d'oro: Giochi estivi e invernali
Mostra il codice Python
#crate a dataset with gold medals
goldMedals = allAthletes[(allAthletes.Medal == 'Gold')]
Mostra il codice Python
goldMedals.sample(5)
| ID | Name | Sex | Age | Height | Weight | Team | NOC | Games | Year | Season | City | Sport | Event | Medal | region | |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 4317 | 2464 | Jo Qesem Ayela Aleh | F | 26.0 | 171.0 | 58.0 | New Zealand | NZL | 2012 Summer | 2012 | Summer | London | Sailing | Sailing Women's Two Person Dinghy | Gold | New Zealand |
| 208777 | 104827 | Vladimir Valeryevich Salnikov | M | 20.0 | 181.0 | 74.0 | Soviet Union | URS | 1980 Summer | 1980 | Summer | Moskva | Swimming | Swimming Men's 1,500 metres Freestyle | Gold | Russia |
| 211730 | 106307 | Luciano Savorini | M | 26.0 | NaN | NaN | Italy | ITA | 1912 Summer | 1912 | Summer | Stockholm | Gymnastics | Gymnastics Men's Team All-Around | Gold | Italy |
| 47089 | 24274 | Bernd Cullmann | M | 20.0 | 180.0 | 71.0 | Germany | GER | 1960 Summer | 1960 | Summer | Roma | Athletics | Athletics Men's 4 x 100 metres Relay | Gold | Germany |
| 206160 | 103490 | Cierra Runge | F | 20.0 | 193.0 | 85.0 | United States | USA | 2016 Summer | 2016 | Summer | Rio de Janeiro | Swimming | Swimming Women's 4 x 200 metres Freestyle Relay | Gold | USA |
Mostra il codice Python
goldMedals.info()
<class 'pandas.core.frame.DataFrame'> Int64Index: 13372 entries, 3 to 271076 Data columns (total 16 columns): ID 13372 non-null int64 Name 13372 non-null object Sex 13372 non-null object Age 13224 non-null float64 Height 10539 non-null float64 Weight 10254 non-null float64 Team 13372 non-null object NOC 13372 non-null object Games 13372 non-null object Year 13372 non-null int64 Season 13372 non-null object City 13372 non-null object Sport 13372 non-null object Event 13372 non-null object Medal 13372 non-null object region 13371 non-null object dtypes: float64(3), int64(2), object(11) memory usage: 1.7+ MB
Mostra il codice Python
missingData(goldMedals)
| Total | Percent | |
|---|---|---|
| Weight | 3118 | 23.317380 |
| Height | 2833 | 21.186060 |
| Age | 148 | 1.106790 |
| region | 1 | 0.007478 |
6.1 Qual è l'età media di chi vince l'oro?
Prima escludo le osservazioni prive del valore Age.
Mostra il codice Python
allAthletesAge = allAthletes[(allAthletes['Age'].notnull())]
Mostra il codice Python
missingData(allAthletesAge)
| Total | Percent | |
|---|---|---|
| Weight | 54263 | 20.739407 |
| Height | 51574 | 19.711667 |
| region | 356 | 0.136064 |
Mostra il codice Python
goldMedals.describe()
| ID | Age | Height | Weight | Year | |
|---|---|---|---|---|---|
| count | 13372.000000 | 13224.000000 | 10539.000000 | 10254.000000 | 13372.000000 |
| mean | 69358.276473 | 25.901013 | 177.898472 | 74.183879 | 1973.131618 |
| std | 39029.340607 | 5.892887 | 11.052521 | 15.207425 | 34.179153 |
| min | 4.000000 | 13.000000 | 136.000000 | 28.000000 | 1896.000000 |
| 25% | 36055.250000 | 22.000000 | 170.000000 | 63.000000 | 1952.000000 |
| 50% | 69076.500000 | 25.000000 | 178.000000 | 73.000000 | 1984.000000 |
| 75% | 103707.000000 | 29.000000 | 185.000000 | 84.000000 | 2002.000000 |
| max | 135553.000000 | 64.000000 | 223.000000 | 170.000000 | 2016.000000 |
L'età media delle righe associate a un oro è 25,9 anni; la mediana è 25 anni.
Mostra il codice Python
plt.figure(figsize=(20, 10))
sns.countplot(x= 'Age', hue='Sex', data=goldMedals )
plt.xticks(rotation = 90)
plt.legend(loc=1, fontsize='x-large')
plt.title('Distribution of Gold Medals by Age and Sex', fontsize = 20)
plt.show()
6.2 Gli ori degli atleti minorenni
Mostra il codice Python
goldMedals['ID'][goldMedals['Age']<18].count()
424
Mostra il codice Python
minorsAthletes = goldMedals[goldMedals['Age']<18]
Mostra il codice Python
plt.figure(figsize=(20, 10))
sns.countplot(x= 'Sport', hue='Sex', data=minorsAthletes)
plt.xticks(rotation = 90)
plt.title('Minors Gold Athletes by Sport', fontsize=20)
plt.legend(loc=1, fontsize='x-large')
plt.show()
Mostra il codice Python
plt.figure(figsize=(20, 10))
sns.countplot(x= 'Event', hue='Sex', data=minorsAthletes)
plt.xticks(rotation=90)
plt.title('Minors Gold Athletes by Event', fontsize=20)
plt.legend(loc=1, fontsize='x-large')
plt.show()
Mostra il codice Python
goldMedals['ID'][goldMedals['Age'] == 13].count()
7
Mostra il codice Python
youngestAthletes = goldMedals[goldMedals['Age'] == 13]
Mostra il codice Python
youngestAthletes
| ID | Name | Sex | Age | Height | Weight | Team | NOC | Games | Year | Season | City | Sport | Event | Medal | region | |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 27207 | 14142 | Hans Bourquin | M | 13.0 | NaN | NaN | Switzerland | SUI | 1928 Summer | 1928 | Summer | Amsterdam | Rowing | Rowing Men's Coxed Pairs | Gold | Switzerland |
| 52010 | 26731 | Donna Elizabeth de Varona (-Pinto) | F | 13.0 | 168.0 | 61.0 | United States | USA | 1960 Summer | 1960 | Summer | Roma | Swimming | Swimming Women's 4 x 100 metres Freestyle Relay | Gold | USA |
| 73581 | 37398 | Fu Mingxia | F | 13.0 | 160.0 | 48.0 | China | CHN | 1992 Summer | 1992 | Summer | Barcelona | Diving | Diving Women's Platform | Gold | China |
| 78544 | 39866 | Marjorie Gestring (-Redlick) | F | 13.0 | NaN | NaN | United States | USA | 1936 Summer | 1936 | Summer | Berlin | Diving | Diving Women's Springboard | Gold | USA |
| 119277 | 60384 | Kim Yun-Mi | F | 13.0 | 160.0 | 48.0 | South Korea | KOR | 1994 Winter | 1994 | Winter | Lillehammer | Short Track Speed Skating | Short Track Speed Skating Women's 3,000 metres... | Gold | South Korea |
| 200704 | 100797 | Aileen Muriel Riggin (-Soule) | F | 13.0 | 142.0 | NaN | United States | USA | 1920 Summer | 1920 | Summer | Antwerpen | Diving | Diving Women's Springboard | Gold | USA |
| 268602 | 134381 | Klaus Zerta | M | 13.0 | 165.0 | 48.0 | Germany | GER | 1960 Summer | 1960 | Summer | Roma | Rowing | Rowing Men's Coxed Pairs | Gold | Germany |
Mostra il codice Python
plt.figure(figsize=(20, 10))
ticks = [0, 1, 2, 3]
sns.countplot(x='Sport', hue='Sex', data=youngestAthletes)
plt.yticks(ticks)
plt.title('Gold Athletes thirteen', fontsize=20)
plt.legend(loc=1, fontsize='x-large')
plt.show()
- Marjorie Gestring aveva 13 anni e 268 giorni quando partecipò ai Giochi di Berlino del 1936 e conquistò l'oro nei tuffi per gli Stati Uniti, secondo il riferimento a Top End Sports nel lavoro originale.
- Nel 1994 la sudcoreana Kim Yun-Mi partecipò a Lillehammer a 13 anni. Vinse la staffetta di short track sui 3.000 metri, diventando la più giovane campionessa dei Giochi invernali secondo Sports Reference.
6.3 Gli atleti più anziani
Mostra il codice Python
goldMedals['ID'][goldMedals['Age'] > 50].count()
65
Mostra il codice Python
oldAthletes = goldMedals[goldMedals['Age'] > 50]
Mostra il codice Python
plt.figure(figsize=(20, 10))
ticks = [0, 5, 10, 15, 20]
plt.yticks(ticks)
sns.countplot(x = 'Sport', hue='Sex', data=oldAthletes)
plt.title('Gold Athletes over 50 by sport', fontsize=20)
plt.legend(loc=1, fontsize='x-large')
plt.show()
6.4 Gli ori nelle diverse edizioni
Mostra il codice Python
plt.figure(figsize=(20, 10))
sns.countplot(x='Year', hue='Season', data=goldMedals)
plt.title('Gold medals per edition of the Games', fontsize = 20)
plt.legend(loc=2, fontsize='x-large')
plt.show()
Nel 1920 il programma comprendeva 156 gare in 29 discipline, distribuite in 22 sport; nel 1924 le gare erano 126, in 23 discipline e 17 sport. Il numero di opportunità di vincere una medaglia cambia quindi fra le edizioni.
6.5 I paesi con più ori
Mostra il codice Python
goldMedals.region.value_counts().reset_index(name='Medal').head(10)
| index | Medal | |
|---|---|---|
| 0 | USA | 2638 |
| 1 | Russia | 1599 |
| 2 | Germany | 1301 |
| 3 | UK | 678 |
| 4 | Italy | 575 |
| 5 | France | 501 |
| 6 | Sweden | 479 |
| 7 | Canada | 463 |
| 8 | Hungary | 432 |
| 9 | Norway | 378 |
Mostra il codice Python
totalGoldMedals = goldMedals.region.value_counts().reset_index(name='Medal').head(5)
sns.catplot(x="index", y="Medal", data=totalGoldMedals,
height=6, kind="bar", palette='afmhot')
plt.xlabel("Countries")
plt.ylabel("Number of Medals")
plt.title('Top 5 Countries', fontsize = 20)
plt.show()
6.6 Altezza e peso di chi vince una medaglia d'oro
Mostra il codice Python
goldMedals.sample(5)
| ID | Name | Sex | Age | Height | Weight | Team | NOC | Games | Year | Season | City | Sport | Event | Medal | region | |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 185323 | 93169 | Marie-Jos Juliana Prec (Hontas-) | F | 24.0 | 180.0 | 60.0 | France | FRA | 1992 Summer | 1992 | Summer | Barcelona | Athletics | Athletics Women's 400 metres | Gold | France |
| 110234 | 55741 | Susanne Jean "Suzy" Jones (-Roy) | F | 20.0 | 168.0 | 58.0 | United States | USA | 1968 Summer | 1968 | Summer | Mexico City | Swimming | Swimming Women's 4 x 100 metres Medley Relay | Gold | USA |
| 215825 | 108359 | Peter Seisenbacher | M | 28.0 | 186.0 | 86.0 | Austria | AUT | 1988 Summer | 1988 | Summer | Seoul | Judo | Judo Men's Middleweight | Gold | Austria |
| 214374 | 107621 | Carolyn Jane Schuler | F | 17.0 | 167.0 | 63.0 | United States | USA | 1960 Summer | 1960 | Summer | Roma | Swimming | Swimming Women's 4 x 100 metres Medley Relay | Gold | USA |
| 42585 | 21972 | William John "Bill" Cleary, Jr. | M | 25.0 | 178.0 | 79.0 | United States | USA | 1960 Winter | 1960 | Winter | Squaw Valley | Ice Hockey | Ice Hockey Men's Ice Hockey | Gold | USA |
Mostra il codice Python
goldMedals.info()
<class 'pandas.core.frame.DataFrame'> Int64Index: 13372 entries, 3 to 271076 Data columns (total 16 columns): ID 13372 non-null int64 Name 13372 non-null object Sex 13372 non-null object Age 13224 non-null float64 Height 10539 non-null float64 Weight 10254 non-null float64 Team 13372 non-null object NOC 13372 non-null object Games 13372 non-null object Year 13372 non-null int64 Season 13372 non-null object City 13372 non-null object Sport 13372 non-null object Event 13372 non-null object Medal 13372 non-null object region 13371 non-null object dtypes: float64(3), int64(2), object(11) memory usage: 2.4+ MB
Mostra il codice Python
goldMedalsHW = goldMedals[(goldMedals['Height'].notnull()) & (goldMedals['Weight'].notnull())]
Mostra il codice Python
markers = {"Summer": "d", "Winter": "h"}
plt.figure(figsize=(15, 15))
sns.scatterplot(x="Height", y="Weight", hue='Sex', style='Season', data=goldMedalsHW, markers=markers)
plt.title('Height VS Weight of Gold Medalists', fontsize=20)
plt.legend(loc=1, fontsize='x-large')
plt.show()
Il grafico mostra una relazione crescente fra altezza e peso per molti degli atleti vincitori di un oro. Controllo ora quali sport praticano quelli con peso superiore a 140 kg.
Mostra il codice Python
goldOver140kg = goldMedalsHW.loc[goldMedalsHW['Weight'] > 140]
Mostra il codice Python
valueCounts(goldOver140kg, ['Sport'])
Weightlifting 12 Athletics 2 Judo 2 Name: Sport, dtype: int64
Mostra il codice Python
goldOver140kg
| ID | Name | Sex | Age | Height | Weight | Team | NOC | Games | Year | Season | City | Sport | Event | Medal | region | |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 4404 | 2511 | Vasily Ivanovich Alekseyev | M | 30.0 | 185.0 | 160.0 | Soviet Union | URS | 1972 Summer | 1972 | Summer | Munich | Weightlifting | Weightlifting Men's Super-Heavyweight | Gold | Russia |
| 4405 | 2511 | Vasily Ivanovich Alekseyev | M | 34.0 | 185.0 | 160.0 | Soviet Union | URS | 1976 Summer | 1976 | Summer | Montreal | Weightlifting | Weightlifting Men's Super-Heavyweight | Gold | Russia |
| 6863 | 3854 | Paul Edward Anderson | M | 24.0 | 178.0 | 141.0 | United States | USA | 1956 Summer | 1956 | Summer | Melbourne | Weightlifting | Weightlifting Men's Heavyweight | Gold | USA |
| 39181 | 20144 | Andrey Ivanovich Chemerkin | M | 24.0 | 183.0 | 170.0 | Russia | RUS | 1996 Summer | 1996 | Summer | Atlanta | Weightlifting | Weightlifting Men's Super-Heavyweight | Gold | Russia |
| 146975 | 73758 | Tomasz Majewski | M | 26.0 | 204.0 | 142.0 | Poland | POL | 2008 Summer | 2008 | Summer | Beijing | Athletics | Athletics Men's Shot Put | Gold | Poland |
| 146976 | 73758 | Tomasz Majewski | M | 30.0 | 204.0 | 142.0 | Poland | POL | 2012 Summer | 2012 | Summer | London | Athletics | Athletics Men's Shot Put | Gold | Poland |
| 196185 | 98498 | Sultanbai Saburovych "Sultan" Rakhmanov | M | 30.0 | 188.0 | 145.0 | Soviet Union | URS | 1980 Summer | 1980 | Summer | Moskva | Weightlifting | Weightlifting Men's Super-Heavyweight | Gold | Russia |
| 199643 | 100282 | Hossein Reza Zadeh | M | 22.0 | 185.0 | 155.0 | Iran | IRI | 2000 Summer | 2000 | Summer | Sydney | Weightlifting | Weightlifting Men's Super-Heavyweight | Gold | Iran |
| 199644 | 100282 | Hossein Reza Zadeh | M | 26.0 | 185.0 | 155.0 | Iran | IRI | 2004 Summer | 2004 | Summer | Athina | Weightlifting | Weightlifting Men's Super-Heavyweight | Gold | Iran |
| 208036 | 104426 | Hitoshi Saito | M | 23.0 | 180.0 | 143.0 | Japan | JPN | 1984 Summer | 1984 | Summer | Los Angeles | Judo | Judo Men's Heavyweight | Gold | Japan |
| 208037 | 104426 | Hitoshi Saito | M | 27.0 | 180.0 | 143.0 | Japan | JPN | 1988 Summer | 1988 | Summer | Seoul | Judo | Judo Men's Heavyweight | Gold | Japan |
| 208622 | 104740 | Behdad Salimi Kordasiabi | M | 22.0 | 192.0 | 160.0 | Iran | IRI | 2012 Summer | 2012 | Summer | London | Weightlifting | Weightlifting Men's Super-Heavyweight | Gold | Iran |
| 228621 | 114810 | Matthias Steiner | M | 25.0 | 183.0 | 146.0 | Germany | GER | 2008 Summer | 2008 | Summer | Beijing | Weightlifting | Weightlifting Men's Super-Heavyweight | Gold | Germany |
| 235494 | 118074 | Lasha Talakhadze | M | 22.0 | 197.0 | 160.0 | Georgia | GEO | 2016 Summer | 2016 | Summer | Rio de Janeiro | Weightlifting | Weightlifting Men's Super-Heavyweight | Gold | Georgia |
| 268659 | 134407 | Leonid Ivanovych Zhabotynskiy | M | 26.0 | 189.0 | 163.0 | Soviet Union | URS | 1964 Summer | 1964 | Summer | Tokyo | Weightlifting | Weightlifting Men's Heavyweight | Gold | Russia |
| 268660 | 134407 | Leonid Ivanovych Zhabotynskiy | M | 30.0 | 189.0 | 163.0 | Soviet Union | URS | 1968 Summer | 1968 | Summer | Mexico City | Weightlifting | Weightlifting Men's Heavyweight | Gold | Russia |
Nel risultato compaiono sollevatori di pesi, con due eccezioni: il lanciatore del peso Tomasz Majewski e il judoka Hitoshi Saito. Passo poi agli atleti alti oltre 200 cm, per verificare quali discipline ricorrono.
Mostra il codice Python
over200cm = goldMedalsHW.loc[goldMedalsHW['Height'] > 200]
Mostra il codice Python
valueCounts(over200cm, ['Sport'])
Basketball 97 Volleyball 34 Water Polo 15 Swimming 14 Rowing 13 Handball 12 Athletics 9 Beach Volleyball 3 Judo 2 Bobsleigh 1 Baseball 1 Canoeing 1 Name: Sport, dtype: int64
Compaiono atleti di pallacanestro e pallavolo: un risultato coerente con le caratteristiche fisiche richieste da questi sport.
7. Gli atleti italiani
Mostra il codice Python
itAthletes = allAthletes[(allAthletes.region == 'Italy')].sort_values('Year')
Mostra il codice Python
itAthletes.info()
<class 'pandas.core.frame.DataFrame'> Int64Index: 10715 entries, 201261 to 158 Data columns (total 16 columns): ID 10715 non-null int64 Name 10715 non-null object Sex 10715 non-null object Age 10321 non-null float64 Height 8045 non-null float64 Weight 7726 non-null float64 Team 10715 non-null object NOC 10715 non-null object Games 10715 non-null object Year 10715 non-null int64 Season 10715 non-null object City 10715 non-null object Sport 10715 non-null object Event 10715 non-null object Medal 10715 non-null object region 10715 non-null object dtypes: float64(3), int64(2), object(11) memory usage: 1.4+ MB
Mostra il codice Python
plt.figure(figsize=(20, 10))
sns.countplot(x='Year', hue='Season',data=itAthletes)
plt.title('Italian athletes per edition of the Games by Season', fontsize = 20)
plt.legend(loc=2, fontsize='x-large')
plt.show()
Mostra il codice Python
plt.figure(figsize=(20, 10))
sns.countplot(x='Year',hue='Sex', data=itAthletes)
plt.title('Italian athletes per edition of the Games by Sex', fontsize = 20)
plt.legend(loc=1, fontsize='x-large')
plt.show()
Mostra il codice Python
itMen = itAthletes[(itAthletes.Sex == 'M')]
itWomen = itAthletes[(itAthletes.Sex == 'F')]
Mostra il codice Python
markers = {"Summer": "d", "Winter": "h"}
plt.figure(figsize=(15, 15))
sns.scatterplot(x="Height", y="Weight", hue='Medal', style='Season', data=itAthletes.sort_values('Year'), markers=markers)
plt.title('Height VS Weight of Olympics Italian Athletes', fontsize=20)
plt.legend(loc=1, fontsize='x-large')
plt.show()
7.1 Gli ori italiani
Mostra il codice Python
goldMedalsITA = itAthletes[(itAthletes.Medal == 'Gold')]
Distribuzione per età
Mostra il codice Python
plt.figure(figsize=(20, 10))
sns.countplot(x='Age', hue='Sex', data=goldMedalsITA)
plt.title('Distribution of Italian Gold Medals by Age', fontsize = 20)
plt.legend(loc=1, fontsize='x-large')
plt.show()
Mostra il codice Python
plt.figure(figsize=(20, 10))
sns.countplot(goldMedalsITA['Age'], color='b')
plt.title('Distribution of Italian Gold Medals by Age', fontsize = 20)
plt.show()
Distribuzione nelle edizioni
Mostra il codice Python
plt.figure(figsize=(20, 10))
sns.countplot(x='Year',hue='Sex', data=goldMedalsITA)
plt.title('Italian Gold medals per edition of the Games', fontsize = 20)
plt.legend(loc=1, fontsize='x-large')
plt.show()
Mostra il codice Python
plt.figure(figsize=(20, 10))
sns.countplot(x='Year', hue='Sex', data=goldMedalsITA)
plt.title('Distribution of Italian Gold Medals by Year', fontsize = 20)
plt.legend(loc=1, fontsize='x-large')
plt.show()
Nota sui conteggi
| Città | Anno | Ori italiani nel medagliere |
|---|---|---|
| Los Angeles | 1984 | 14 |
| Roma | 1960 | 13 |
| Anversa | 1920 | 13 |
Nel conteggio delle righe del dataset Anversa 1920 risulta particolarmente alta. Questo è però un archivio di atleti: l'oro nella ginnastica a squadre compare per ciascun componente della squadra. Il riferimento storico del lavoro originale è Wikipedia. Le righe con Gold non corrispondono necessariamente al numero di gare vinte nel medagliere.
Mostra il codice Python
goldMedalsITA.Event.value_counts().reset_index(name='Medal').head(10)
| index | Medal | |
|---|---|---|
| 0 | Gymnastics Men's Team All-Around | 58 |
| 1 | Fencing Men's epee, Team | 47 |
| 2 | Fencing Men's Foil, Team | 38 |
| 3 | Water Polo Men's Water Polo | 33 |
| 4 | Cycling Men's Team Pursuit, 4,000 metres | 29 |
| 5 | Fencing Men's Sabre, Team | 25 |
| 6 | Fencing Women's Foil, Team | 15 |
| 7 | Rowing Men's Coxed Fours | 15 |
| 8 | Football Men's Football | 14 |
| 9 | Water Polo Women's Water Polo | 13 |
La ginnastica a squadre spiega il peso di quell'edizione nel conteggio delle righe. Divido ora le osservazioni con medaglia d'oro fra uomini e donne.
Mostra il codice Python
itGoldMen = goldMedalsITA[(goldMedalsITA.Sex == 'M')]
itGoldWomen = goldMedalsITA[(goldMedalsITA.Sex == 'F')]
Mostra il codice Python
plt.figure(figsize=(20, 10))
sns.countplot(x='Year', data=itGoldMen, color='b')
plt.title('Male Italian Gold medals per edition of the Games', fontsize = 20)
plt.show()
Mostra il codice Python
plt.figure(figsize=(20, 10))
sns.countplot(x='Year', data=itGoldWomen, color='r')
plt.title('Female Italian Gold medals per edition of the Games', fontsize = 20)
plt.show()
Mostra il codice Python
plt.figure(figsize=(30,20))
#1
plt.subplot(221)
sns.countplot(x='Year', hue='Season', data=itMen)
plt.xticks(rotation=90)
plt.title('Italian Men per edition of the Games', fontsize = 20)
plt.legend(loc=2, fontsize='large')
#2
plt.subplot(222)
sns.countplot(x='Year', hue='Season', data=itWomen)
plt.xticks(rotation=90)
plt.title('Italian Women per edition of the Games', fontsize = 20)
plt.legend(loc=2, fontsize='large')
#3
plt.subplot(223)
sns.countplot(x='Year', hue='Season', data=itGoldMen)
plt.xticks(rotation=90)
plt.title('Male Italian Gold medals per edition of the Games', fontsize = 20)
plt.legend(loc=2, fontsize='large')
#4
plt.subplot(224)
sns.countplot(x='Year', hue='Season', data=itGoldWomen)
plt.xticks(rotation=90)
plt.title('Female Italian Gold medals per edition of the Games', fontsize = 20)
plt.legend(loc=2, fontsize='large')
plt.show()
Variazione di peso e altezza degli italiani vincitori di oro
Mostra il codice Python
markers = {"Summer": "d", "Winter": "h"}
plt.figure(figsize=(15, 15))
sns.scatterplot(x="Height", y="Weight", hue='Sex',style='Season', data=goldMedalsITA)
plt.title('Height VS Weight of Italian Gold Medals', fontsize=20)
plt.show()
Sviluppi successivi
Il notebook originale si concludeva con l'intenzione di proseguire l'analisi. La raccolta qui conservata copre il periodo 1896–2016.
Mostra il codice Python
Approfondimenti metodologici
Questa analisi complementare conserva gli approfondimenti già pubblicati sul sito. Ha un notebook indipendente: usa il download dedicato per ripeterla. Le celle precedenti corrispondono invece al lavoro completo pubblicato su Kaggle.
Prima domanda: che cosa stiamo contando?
La raccolta storica comprende risultati dal 1896 al 2016. Una riga descrive un atleta in una gara: la stessa persona può comparire più volte nella stessa edizione e in edizioni diverse. Contare le righe come atleti o come medaglie produce risultati ingannevoli, soprattutto negli sport di squadra.
Questa edizione conserva il perimetro storico della fonte e aggiorna i conteggi e le spiegazioni. Non aggiunge Tokyo, Pechino o Parigi attraverso tabelle con struttura diversa. Le competizioni artistiche e i Giochi intercalati del 1906 sono presenti nel file: per il confronto sportivo principale li escludo esplicitamente. Questo modifica il perimetro rispetto ad alcune figure storiche del sito.
Come riprodurre l'analisi
Questa è l'edizione italiana revisionata l'8 ottobre 2026. Il notebook inglese usa lo stesso codice e gli stessi dati. Eseguire le celle dall'alto verso il basso in Jupyter, con Python 3.11 o successivo. Ambiente verificato: NumPy 2.2.6, pandas 2.2.3, Matplotlib 3.10.3 e scikit-learn 1.7.2. Per installarlo: pip install numpy==2.2.6 pandas==2.2.3 matplotlib==3.10.3 scikit-learn==1.7.2 ipykernel.
Installare le librerie prima di avviare Jupyter. Su Kaggle uso l'ambiente della piattaforma senza sostituire pacchetti già caricati: la prima cella stampa le versioni effettive, che possono differire da quelle locali indicate sopra. I risultati delle due edizioni sono verificati separatamente.
Il primo caricamento richiede Internet; in seguito i file vengono letti dalla cartella dati. Su Kaggle vengono cercati prima nei dataset collegati. L'impronta SHA256 controlla che il file sia quello dell'analisi: se la fonte cambia, l'esecuzione si ferma invece di produrre risultati diversi senza avvisare. I nomi originali delle colonne restano nel codice; titoli, grafici e lettura dei risultati sono in italiano.
Mostra il codice Python
LANG = "it"
from pathlib import Path
from io import BytesIO
import gzip
import hashlib
import os
import platform
import zipfile
from urllib.request import Request, urlopen
import importlib.metadata
# Use the running environment. Kaggle can preload NumPy before the first cell;
# replacing it with pip here would mix loaded binaries and newly installed files.
# For a pinned local environment, install requirements before starting Jupyter.
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
from IPython.display import display
SEED = 42
def label(it, en):
return it if LANG == "it" else en
plt.rcParams.update({"figure.figsize": (10, 4.5), "figure.dpi": 130,
"axes.spines.top": False, "axes.spines.right": False,
"axes.prop_cycle": plt.cycler(color=["#b54d35", "#24576b", "#947320", "#627e45"])})
pd.set_option("display.max_columns", 12)
pd.set_option("display.max_rows", 18)
pd.set_option("display.float_format", lambda x: f"{x:,.3f}")
CACHE = Path(os.environ.get("ANALISI_DATI_DIR", "dati"))
CACHE.mkdir(parents=True, exist_ok=True)
def read_data(name, url, sha256):
# Prefer attached Kaggle inputs or a verified local copy.
candidates = [CACHE / name]
if Path("/kaggle/input").exists():
candidates += sorted(Path("/kaggle/input").rglob(name))
raw = None
for path in candidates:
if path.is_file() and hashlib.sha256(path.read_bytes()).hexdigest() == sha256:
raw = path.read_bytes()
break
if raw is None:
request = Request(url, headers={"User-Agent": "StefanoNocco-DataAnalysis/1.0"})
with urlopen(request, timeout=90) as response:
raw = response.read()
if zipfile.is_zipfile(BytesIO(raw)):
with zipfile.ZipFile(BytesIO(raw)) as archive:
matches = [p for p in archive.namelist() if Path(p).name == name]
if len(matches) != 1:
raise ValueError(f"Expected exactly one file: {name}")
raw = archive.read(matches[0])
elif raw[:2] == b"\x1f\x8b":
raw = gzip.decompress(raw)
if hashlib.sha256(raw).hexdigest() != sha256:
raise ValueError(f"Source changed: {name}. Review data and update the recorded hash.")
(CACHE / name).write_bytes(raw)
return pd.read_csv(BytesIO(raw))
print(label("Versione Python:", "Python version:"), platform.python_version())
for package in ["numpy", "pandas", "matplotlib", "scikit-learn", "scipy"]:
print(package, importlib.metadata.version(package))
Versione Python: 3.11.14 numpy 2.2.6 pandas 2.2.3 matplotlib 3.10.3 scikit-learn 1.7.2 scipy 1.15.3
Mostra il codice Python
URL = "https://www.kaggle.com/api/v1/datasets/download/heesoo37/120-years-of-olympic-history-athletes-and-results"
raw = read_data("athlete_events.csv", URL, "1751e89b509dd8c0fa0979ee258eef4374aa93f17d64cd07383ad3f57c5aabd7")
regions = read_data("noc_regions.csv", URL, "d9be65009dd12851058119cfc1df207cf64ce9c5dd2c3cd85bb95342f59c47f7")
assert regions["NOC"].is_unique
print(label("Righe originali:", "Original rows:"), len(raw))
print(label("Duplicati completi:", "Exact duplicates:"), raw.duplicated().sum())
df = raw.drop_duplicates().copy()
df = df[~df["Sport"].eq("Art Competitions") & df["Year"].ne(1906)]
df = df.merge(regions[["NOC", "region"]], on="NOC", how="left", validate="many_to_one")
print(label("Righe nel perimetro sportivo:", "Rows in sporting scope:"), len(df))
display(df[["Age", "Height", "Weight", "region"]].isna().mean().mul(100).round(1).rename(
label("Mancanti (%)", "Missing (%)")).to_frame())
Righe originali: 271116 Duplicati completi: 1385
Righe nel perimetro sportivo: 265735
| Mancanti (%) | |
|---|---|
| Age | 3.100 |
| Height | 20.700 |
| Weight | 21.700 |
| region | 0.100 |
Una persona per edizione
Per contare i partecipanti uso la coppia ID–Games. Per età, sesso, altezza e peso controllo prima che non ci siano valori discordanti della stessa persona nella stessa edizione. Se esistessero, sarebbe necessario risolverli prima di scegliere una riga.
La percentuale femminile usa il numero di atlete diviso per tutti i partecipanti dell'edizione. Il dataset registra sesso con le categorie F e M; questa è una caratteristica della fonte storica, non una descrizione completa dell'identità delle persone. Tengo separate Olimpiadi estive e invernali, che hanno programmi diversi.
Mostra il codice Python
person_key = ["ID", "Games"]
conflicts = df.groupby(person_key)[["Sex", "Age", "Height", "Weight"]].nunique().gt(1).sum()
assert conflicts.eq(0).all(), conflicts.to_dict()
people = df.sort_values(["ID", "Year"]).drop_duplicates(person_key)
counts = people.groupby(["Year", "Season", "Sex"]).size().unstack(fill_value=0)
counts["total"] = counts["F"] + counts["M"]
counts["female_pct"] = counts["F"] / counts["total"] * 100
fig, axes = plt.subplots(1, 2, figsize=(11, 4))
for season, group in counts.groupby(level="Season"):
years = group.index.get_level_values("Year")
name = label("Estive", "Summer") if season == "Summer" else label("Invernali", "Winter")
axes[0].plot(years, group["total"], marker=".", label=name)
axes[1].plot(years, group["female_pct"], marker=".", label=name)
axes[0].set(ylabel=label("Atleti distinti per edizione", "Unique athletes per edition"), xlabel=label("Anno", "Year"))
axes[1].set(ylabel=label("Partecipazione femminile (%)", "Female participation (%)"), xlabel=label("Anno", "Year"), ylim=(0, 100))
axes[0].legend(); axes[1].legend(); plt.tight_layout(); plt.show()
display(counts.groupby(level="Season").tail(3))
| Sex | F | M | total | female_pct | |
|---|---|---|---|---|---|
| Year | Season | ||||
| 2006 | Winter | 955 | 1539 | 2494 | 38.292 |
| 2008 | Summer | 4609 | 6290 | 10899 | 42.288 |
| 2010 | Winter | 1033 | 1503 | 2536 | 40.733 |
| 2012 | Summer | 4654 | 5863 | 10517 | 44.252 |
| 2014 | Winter | 1102 | 1643 | 2745 | 40.146 |
| 2016 | Summer | 5034 | 6145 | 11179 | 45.031 |
Età e misure fisiche: il problema dei mancanti
Una media generale può cambiare perché cambia il programma olimpico, non soltanto perché cambiano gli atleti. Inoltre altezza e peso non sono registrati con la stessa completezza in tutte le epoche. Mostro la copertura prima di confrontare le mediane; non riempio i vuoti con una media globale.
Per il confronto per sport uso una persona per edizione e sport, dal 1960, con altezza e peso entrambi presenti. Richiedo almeno 100 osservazioni per gruppo, una soglia di leggibilità e non una garanzia statistica. Le mediane descrivono il sottoinsieme misurato, non un ideale fisico né una relazione causale con la vittoria.
Mostra il codice Python
coverage = people.assign(measured=people["Height"].notna() & people["Weight"].notna()).groupby(
["Year", "Season"]).agg(athletes=("ID", "size"), measured_pct=("measured", "mean"), median_age=("Age", "median"))
coverage["measured_pct"] *= 100
display(coverage.groupby(level="Season").agg({"measured_pct": ["min", "max"], "median_age": ["min", "max"]}).round(1))
sport_people = df[df["Year"].ge(1960)].drop_duplicates(["ID", "Games", "Sport"])
measured = sport_people.dropna(subset=["Height", "Weight"])
physical = measured.groupby(["Sport", "Sex"]).agg(n=("ID", "size"), height_cm=("Height", "median"),
weight_kg=("Weight", "median"), age_years=("Age", "median"))
display(physical[physical["n"].ge(100)].sort_values("n", ascending=False).head(14).round(1))
| measured_pct | median_age | |||
|---|---|---|---|---|
| min | max | min | max | |
| Season | ||||
| Summer | 2.900 | 99.600 | 22.500 | 26.000 |
| Winter | 7.500 | 99.400 | 23.000 | 26.000 |
| n | height_cm | weight_kg | age_years | ||
|---|---|---|---|---|---|
| Sport | Sex | ||||
| Athletics | M | 14430 | 180.000 | 72.000 | 25.000 |
| F | 8623 | 170.000 | 58.000 | 25.000 | |
| Rowing | M | 5321 | 189.000 | 87.000 | 25.000 |
| Swimming | M | 5119 | 185.000 | 78.000 | 21.000 |
| Cycling | M | 4729 | 178.000 | 72.000 | 24.000 |
| Wrestling | M | 4554 | 172.000 | 74.000 | 25.000 |
| Boxing | M | 4244 | 172.000 | 63.000 | 23.000 |
| Shooting | M | 4199 | 176.000 | 77.000 | 32.000 |
| Swimming | F | 4037 | 171.000 | 61.000 | 19.000 |
| Sailing | M | 3836 | 180.000 | 77.000 | 29.000 |
| Ice Hockey | M | 3635 | 181.000 | 84.000 | 26.000 |
| Football | M | 3302 | 178.000 | 73.000 | 22.000 |
| Canoeing | M | 3200 | 181.000 | 80.000 | 25.000 |
| Hockey | M | 2770 | 177.000 | 74.000 | 25.000 |
Ori: atleti premiati e gare vinte
Una squadra vincitrice genera una riga per atleta. Per l'Italia confronto due misure: partecipazioni premiate con l'oro e gare con almeno un oro italiano. La seconda usa Games–Event per NOC = ITA: una squadra vale una gara vinta.
Questo è un conteggio di gare vinte nella raccolta, non un algoritmo universale per ricostruire il medagliere: parità, equipaggi misti e cambiamenti nei comitati richiedono attenzione. Non sostituisco retroattivamente i comitati storici con le nazioni attuali della tabella geografica.
Mostra il codice Python
italian_gold = df[df["NOC"].eq("ITA") & df["Medal"].eq("Gold")]
awarded = italian_gold.groupby(["Year", "Season"]).size().rename("athlete_entries")
events = italian_gold.drop_duplicates(["Games", "Event"]).groupby(["Year", "Season"]).size().rename("events_won")
italy = pd.concat([awarded, events], axis=1)
display(italy.loc[([1920, 1960, 1984, 2016], slice(None)), :])
ax = italy.xs("Summer", level="Season").plot.bar(figsize=(12, 4))
ax.set(xlabel=label("Edizione estiva", "Summer edition"), ylabel=label("Conteggio", "Count"))
ax.legend([label("Partecipazioni premiate", "Awarded athlete entries"), label("Gare vinte", "Events won")])
plt.tight_layout(); plt.show()
| athlete_entries | events_won | ||
|---|---|---|---|
| Year | Season | ||
| 1920 | Summer | 66 | 13 |
| 1960 | Summer | 36 | 13 |
| 1984 | Summer | 29 | 14 |
| Winter | 2 | 2 | |
| 2016 | Summer | 8 | 8 |
Medagliati ed età
La mediana dell'età dei vincitori cambia se chi vince più gare viene contato più volte. Per il riepilogo finale torno quindi alle persone per edizione. I confronti fra vincitori e partecipanti non isolano l'effetto dell'età: composizione per sport, epoca e sesso sono diverse. Le celle permettono di controllare anche la copertura, così una mediana non nasconde quanti valori mancano.
Mostra il codice Python
gold_people = df[df["Medal"].eq("Gold")].drop_duplicates(person_key)
display(pd.DataFrame([
{"group": label("Tutti i partecipanti", "All participants"), "n": len(people),
"age_observed": people["Age"].notna().sum(), "median_age": people["Age"].median()},
{"group": label("Vincitori di almeno un oro", "At least one gold"), "n": len(gold_people),
"age_observed": gold_people["Age"].notna().sum(), "median_age": gold_people["Age"].median()}
]).set_index("group"))
| n | age_observed | median_age | |
|---|---|---|---|
| group | |||
| Tutti i partecipanti | 184569 | 178650 | 25.000 |
| Vincitori di almeno un oro | 12000 | 11898 | 25.000 |
Conclusioni e fonti
Ad Anversa 1920 la raccolta contiene 66 partecipazioni italiane premiate con l'oro, corrispondenti a 13 gare vinte nel perimetro sportivo. Contare le 66 righe come 66 ori di medagliere moltiplicherebbe le vittorie di squadra. Il riscontro con l'archivio CONI aiuta a verificare il significato del conteggio.
La crescita della partecipazione e della presenza femminile emerge meglio quando ogni atleta viene contato una volta per edizione. Il confronto degli ori italiani mostra invece quanto le righe degli sport di squadra gonfino un conteggio ingenuo. Le caratteristiche fisiche restano condizionate dalla copertura e dal programma delle discipline.
I dati si fermano al 2016: questa revisione migliora il metodo, non presenta il quadro olimpico attuale. Per estendere la serie occorrerebbe armonizzare identificativi, eventi e comitati delle nuove edizioni, documentando le corrispondenze.
- 120 years of Olympic history, rgriffin su Kaggle: raccolta storica derivata da Sports-Reference.
- Anversa 1920, archivio CONI: riscontro per i 13 ori italiani nelle competizioni sportive.