image_output_1.png
import matplotlib.pyplot as plt

import pandas as pd

df1 = pd.read_csv('../input/120-years-of-olympic-history-athletes-and-results/athlete_events.csv')
df2 = pd.read_csv('../input/120-years-of-olympic-history-athletes-and-results/noc_regions.csv')

df = pd.merge(df1, df2, left_on='NOC', right_on='NOC')
df = df.query('Season == "Summer"')

df.replace('USA', 'United States of America', inplace=True)
df.replace('Tanzania', 'United Republic of Tanzania', inplace=True)
df.replace('Democratic Republic of Congo', 'Democratic Republic of the Congo', inplace=True)
df.replace('Congo', 'Republic of the Congo', inplace=True)
df.replace('Lao', 'Laos', inplace=True)
df.replace('Syrian Arab Republic', 'Syria', inplace=True)
df.replace('Serbia', 'Republic of Serbia', inplace=True)
df.replace('Czechia', 'Czech Republic', inplace=True)
df.replace('UAE', 'United Arab Emirates', inplace=True)
df.replace('UK', 'United Kingdom', inplace=True)
def Pays_Hebergeur(col):
    if col == 'Rio de Janeiro':
        return 'Brazil'
    elif col == 'London':
        return 'United Kingdom'
    elif col == 'Beijing':
        return 'China'
    elif col == 'Athina':
        return 'Greece'
    elif col == 'Sydney' or col == 'Melbourne':
        return 'Australia'
    elif col == 'Atlanta' or col == 'Los Angeles' or col == 'St. Louis':
        return 'United States of America'
    elif col == 'Barcelona':
        return 'Spain'
    elif col == 'Seoul':
        return 'South Korea'
    elif col == 'Moskva':
        return 'Russia'
    elif col == 'Montreal':
        return 'Canada'
    elif col == 'Munich' or col == 'Berlin':
        return 'Germany'
    elif col == 'Mexico City':
        return 'Mexico'
    elif col == 'Tokyo':
        return 'Japan'
    elif col == 'Roma':
        return 'Italy'
    elif col == 'Paris':
        return 'France'
    elif col == 'Helsinki':
        return 'Finland'
    elif col == 'Amsterdam':
        return 'Netherlands'
    elif col == 'Antwerpen':
        return 'Belgium'
    elif col == 'Stockholm':
        return 'Sweden'
    else:
        return 'Other'
df['Pays_Hebergeur'] = df['City'].apply(Pays_Hebergeur)

def plot_medals_by_country(country):
    country_team = df[df['Team'] == country]
    country_host = df[(df['Team'] == country) & (df['Pays_Hebergeur'] == country)]
    country_team_grouped = country_team.groupby('Year')['Medal'].sum()
    country_host_sum = country_host.groupby('Year')['Medal'].sum()

plot_medals_by_country('Spain')