<jupyter_start><jupyter_text>All Time Olympic Games Medals  Business Understanding The Olympic Games is an important international event held every four years. In this analysis we will be interested for all Olympic Games from 1896 to 2018. We will try answering the following questions :1) Which country has won the most gold medals in summer games ?2) Which country had the biggest difference between their summer and winter gold medal counts ?3) Which country has the biggest difference between their summer gold medal counts and winter gold medal counts relative to their total gold medal count ?4) Which are the top 5 countries if we weights each gold medal for 3 points, silver medals for 2 points, and bronze medals for 1 point ?  Data Understanding and Data Preparation The following code loads the olympics dataset (olympics.csv), which was derrived from the Wikipedia entry on All Time Olympic Games Medals, and does some basic data cleaning.The columns are organized as  of Summer games, Summer medals,  of Winter games, Winter medals, total  number of games, total  of medals.<jupyter_code>#import necessary libraries
import pandas as pd
import matplotlib.pyplot as plt
%matplotlib notebook
# read the dataset an make some cleaning and store in 'df'
df = pd.read_csv('olympics.csv', index_col=0, skiprows=1)

# renaming columns to make it more readable
for col in df.columns:
    if col[:2]=='01':
        df.rename(columns={col:'Gold'+col[4:]}, inplace=True)
    if col[:2]=='02':
        df.rename(columns={col:'Silver'+col[4:]}, inplace=True)
    if col[:2]=='03':
        df.rename(columns={col:'Bronze'+col[4:]}, inplace=True)
    if col[:1]=='№':
        df.rename(columns={col:'#'+col[1:]}, inplace=True)

names_ids = df.index.str.split('\s\(') # split the index by '('

df.index = names_ids.str[0] # the [0] element is the country name (new index) 
df['ID'] = names_ids.str[1].str[:3] # the [1] element is the abbreviation or ID (take first 3 characters from that)

df = df.drop('Totals')
#display first five rows of the dataset
df.head()
# note : that there is no missing values
df.isnull().sum()
# df shape
df.shape<jupyter_output><empty_output><jupyter_text>Answer Questions  Question 1Which country has won the most gold medals in summer games ?<jupyter_code>def most_gold():
    '''
    This function has no inputs and returns a coutry name as a string. 
    '''
    
    return df['Gold'].idxmax()

most_gold()<jupyter_output><empty_output><jupyter_text>Question 2Which country had the biggest difference between their summer and winter gold medal counts ?<jupyter_code>def biggest_diff():
    '''
    This function has no inputs and returns a coutry name as a string.  
    '''
    
    return (df['Gold'] - df['Gold.1']).abs().idxmax()

biggest_diff()<jupyter_output><empty_output><jupyter_text>Question 3Which country has the biggest difference between their summer gold medal counts and winter gold medal counts relative to their total gold medal count ? (This includes countries that have won at least 1 gold in both summer and winter)<jupyter_code>def relative_biggest_diff():
    '''
    This function has no inputs and returns a coutry name as a string.  
    '''
    
    new_df = df[(df['Gold']>0) & (df['Gold.1']>0)]
    
    return ((new_df['Gold'] - new_df['Gold.1']).abs()/new_df['Gold.2']).idxmax() 
    
relative_biggest_diff()<jupyter_output><empty_output><jupyter_text>Question 4Which are the top 5 countries if we weights each gold medal for 3 points, silver medals for 2 points, and bronze medals for 1 point ?<jupyter_code>def top_five():
    '''
    This function has no inputs and returns a pandas Series with the top 5 countries as index and their scores as values.  
    '''
    
    return (df['Gold.2']*3 + df['Silver.2']*2 + df['Bronze.2']).sort_values(ascending=False)[:5]

top5 = top_five()
    
# make  a plot
fig, ax = plt.subplots(figsize=(10,6))
bars = plt.bar(top5.index, top5)
ax.set_title('Top five countries in Olympic Games (weighted medals)\n Gold = 3pts, Silver = 2pts and Bronze = 1pt')
ax.spines['right'].set_visible(False)
ax.spines['top'].set_visible(False)
plt.gca().axes.get_yaxis().set_ticks([])
ax.tick_params(bottom=False)

for bar in bars:
    height = bar.get_height()
    ax.text(bar.get_x() + bar.get_width()/2., height,'%d' % int(height), ha='center', va='bottom')<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.11225422953818015, 'fraction_numerical': 0.01600365797896662, 'mean_word_length': 4.523989898989899, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 23, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '5', 'dir': 'jupyter-structured-clean-dedup', 'id': '297016', 'license': 'CNRI-Python', 'n_tokens_mistral': 1382, 'n_tokens_neox': 1318, 'n_words': 501, 'path': 'Olympic_Games_Medals.ipynb', 'repo_name': 'Amine13u/All-Time-Olympic-Games-Medals', 'size': '4374'}