NotesWhat is notes.io?

Notes brand slogan

Notes - notes.io

def get_medals_gb_year_country():
""" Group by edition and country and sum medals count.
"""
medals_groupedBy_yearCountry = olympics.groupby(['Edition','Code']).apply(lambda country: country['Code'].count())
return medals_groupedBy_yearCountry

def get_medals_gb_year_country_medal():
""" Group by edition, country, medal type and sum medals count.
"""
medals_groupedBy_yearCountryMedal = olympics.groupby(['Edition', 'Code', 'Medal']).apply(lambda country: country['Medal'].count())
return medals_groupedBy_yearCountryMedal

def get_medals_last_10_years(countrycode):
""" Get Gold, Silver and Bronze medals for a country for last 10 editions.
"""
last10pics = olympics['Edition'].unique()
yrs = pd.Series(last10pics).nlargest(10)
df = pd.DataFrame([], columns=['Year', 'Gold', 'Silver', 'Bronze'])
medalsdf = get_medals_gb_year_country_medal()

for yr in yrs:
medaltally = medalsdf[yr][countrycode]
gold = 0
silver = 0
bronze = 0
if 'Gold' in medaltally:
gold = medaltally['Gold']
if 'Silver' in medaltally:
silver = medaltally['Silver']
if 'Bronze' in medaltally:
bronze = medaltally['Bronze']
df1 = pd.DataFrame([[yr,gold, silver, bronze]], columns=['Year', 'Gold', 'Silver', 'Bronze'])
df = df.append(df1, ignore_index=True)
df = df.sort_values(by=['Year'], ascending=True)
df = df.reset_index()
del df['index']

return df

def get_correlation_medalstally():
""" Get correlation between the medals tally and population, GDP per capita.
"""
df = get_medals_gb_year_country()
values = get_all_olympic_years().values
size = values.size
correlations = []
for i in range(size):
year = values[i][0]
df1 = df[year].to_frame(name="Tally")
df1 = df1.reset_index()
df2 = pd.merge(df1,dictionary, on='Code')
corrpop = df2.corr().values[0][1]
corrgdp = df2.corr().values[0][2]
resp = {"Year": year, "Population":corrpop, "GDP":corrgdp}
correlations.append(resp)
return correlations

def get_medals_category(countrycode, year):
""" Get the medals count in different sports category for a country in an edition.
"""
df = olympics[olympics['Edition'] == year]
df1 = df[df['Code'] == countrycode]
df2 = df1.groupby(['Sport']).apply(lambda country: country['Medal'].count())
return df2

def get_medals_category_all(countrycode):
""" Get the medals count in different sports category for a country for last ten editions.
"""
df1 = olympics[olympics['Code'] == countrycode]
df2 = df1.groupby(['Sport']).apply(lambda country: country['Medal'].count())
return df2

def get_top_ten_gold_tally(year):
""" Get the top ten gold medal winning countries in an edition.
"""
df = olympics[olympics['Edition'] == year]
df1 = df[df['Medal'] == 'Gold']
df2 = df1.groupby(['Code']).apply(lambda country: country['Medal'].count())
return df2

def get_top_ten_total_tally(year):
""" Get the top ten total medal winning countries in an edition.
"""
df = olympics[olympics['Edition'] == year]
df1 = df.groupby(['Code']).apply(lambda country: country['Medal'].count())
return df1

def get_year_venue():
""" Get edition venue matrix.
"""
df = olympics[['Edition', 'City']]
df = df.drop_duplicates()
df = df.reset_index()
df = df.set_index('Edition')
del df['index']
return df.sort_index()

def get_all_olympic_years():
""" Get list of all olympic editions.
"""
df = olympics['Edition']
df = df.drop_duplicates()
df = df.reset_index()
del df['index']
return df.sort_index()

def get_all_countries():
""" Get list of all countries.
"""
df = olympics[['Code','Country']]
df = df.drop_duplicates()
df = df.reset_index()
del df['index']
return df.sort(['Country'],ascending=[True])

def get_country_edition_data(countrycode,edition):
""" Get data for a country and edition.
"""
df = olympics[olympics["Code"] == countrycode]
df1 = df[df["Edition"] == edition]
return df1
     
 
what is notes.io
 

Notes.io is a web-based application for taking notes. You can take your notes and share with others people. If you like taking long notes, notes.io is designed for you. To date, over 8,000,000,000 notes created and continuing...

With notes.io;

  • * You can take a note from anywhere and any device with internet connection.
  • * You can share the notes in social platforms (YouTube, Facebook, Twitter, instagram etc.).
  • * You can quickly share your contents without website, blog and e-mail.
  • * You don't need to create any Account to share a note. As you wish you can use quick, easy and best shortened notes with sms, websites, e-mail, or messaging services (WhatsApp, iMessage, Telegram, Signal).
  • * Notes.io has fabulous infrastructure design for a short link and allows you to share the note as an easy and understandable link.

Fast: Notes.io is built for speed and performance. You can take a notes quickly and browse your archive.

Easy: Notes.io doesn’t require installation. Just write and share note!

Short: Notes.io’s url just 8 character. You’ll get shorten link of your note when you want to share. (Ex: notes.io/q )

Free: Notes.io works for 12 years and has been free since the day it was started.


You immediately create your first note and start sharing with the ones you wish. If you want to contact us, you can use the following communication channels;


Email: [email protected]

Twitter: http://twitter.com/notesio

Instagram: http://instagram.com/notes.io

Facebook: http://facebook.com/notesio



Regards;
Notes.io Team

     
 
Shortened Note Link
 
 
Looding Image
 
     
 
Long File
 
 

For written notes was greater than 18KB Unable to shorten.

To be smaller than 18KB, please organize your notes, or sign in.