# ---
# jupyter:
#   jupytext:
#     text_representation:
#       extension: .py
#       format_name: light
#       format_version: '1.5'
#       jupytext_version: 1.14.4
#   kernelspec:
#     display_name: Python 3
#     language: python
#     name: python3
# ---

# # Summer Olympics Data Analysis Project
# # Guided by EliteTechnoGroup

# ### 1. In how many cities Summer Olympics is held so far?

import pandas as pd

df = pd.read_csv('summer.csv')

# the cities having summer olympics held 
  # is 22

df['City'].unique()

len(df['City'].unique())

# +
# the countries where  summer olympics are held 
# is 148
# -

df['Country'].unique()

len(df['Country'].unique())

data = df.values

df.head()

len(df['Country'].unique())

# ### 2. Which sport is having most number of Gold Medals so far? (Top 5)



len(df['Sport'])

data = []
for Sport in df['Sport'].unique():
    data.append([ Sport , len(df[df['Sport'] == Sport])])
    

gold = pd.DataFrame(data , columns = ['Sport','Medal']).sort_values(by = 'Medal' , ascending = False)

gold

gold.head().plot( x = 'Sport' , y = 'Medal' ,kind = 'bar')



# ### 3. Which sport is having most number of medals so far? (Top 5)

data = []
for Sport in df['Sport'].unique():
    data.append([ Sport , len(df[df['Sport'] == Sport])])
sport = pd.DataFrame(data , columns = ['Sport','Medal']).sort_values(by = 'Medal' , ascending = False).head()

sport

sport.head().plot( x = 'Sport' , y = 'Medal' ,kind = 'bar',figsize = (5,5))

df.head()

# ### 4. Which player has won most number of medals? (Top 5)

df['Athlete'].unique()

player = df.groupby('Athlete')['Medal'].count().sort_values(ascending=False)

player.head().plot( x = 'Athlete' , y = 'Medal' ,kind = 'bar')

# ### 5. Which player has won most number Gold Medals of medals? (Top 5)



gold = df[df['Medal']=='Gold'].groupby('Athlete').count().sort_values(['Medal'],ascending=False)

gold['Medal'].head().plot( x = 'Athlete' , y = 'Medal' ,kind = 'bar' )



# ### 6. In which year India won first Gold Medal in Summer Olympics?

india = df[df['Country']=='IND']

INDgold = india[india['Medal']=='Gold'].sort_values(['Year'] , ascending=True)

print(INDgold['Year'].head(1))

# ### 7. Which event is most popular in terms on number of players? (Top 5)

data = []
for Event in df['Event'].unique():
    data.append([ Event , len(df[df['Event'] == Event])])
event = pd.DataFrame(data , columns = ['Event','Freq']).sort_values(by = 'Freq' , ascending = False)

event

event.head().plot( x = 'Event' , y = 'Freq' ,kind = 'bar' )

# ### 8. Which sport is having most female Gold Medalists? (Top 5)

# +
gold = df[df['Medal']=='Gold']

femalegold = gold[gold['Gender']=='Women'].groupby('Athlete').count().sort_values(['Medal'],ascending=False)
# -

femalegold['Medal'].head().plot( x = 'Sport' , y = 'Medal' ,kind = 'bar' )



StarcoderdataJupyterScriptsDedupFiltered