Homework 5 For this homework you are required to use Python (Spyder is recommended). Deadline: Now ~ 10/16/2021 9:00PM (You will have 3 days and 7 hours to work on this assignment) Please answer and...

1 answer below »
I have attached two docs. please read


Homework 5 For this homework you are required to use Python (Spyder is recommended). Deadline: Now ~ 10/16/2021 9:00PM (You will have 3 days and 7 hours to work on this assignment) Please answer and explain clearly for each sub question. (Format like question 1: your code and solution. Question 2: code and solution. Question 3…) Contact information: [email protected] if you have any question This is a historical dataset on the modern Olympic Games, including all the Games from Athens 1896 to Rio de Janeiro 2016. The olympics data set is posted on D2L, it contains a list of medallists at the Games of the Olympiad per edition, sport, discipline, gender and event. Use the data and answer the following questions. 1.Which country has won the most female's gold medals in singles tennis over the years? 2. In which events did Jesse Owens win a medal? 3. Sort the results alphabetically by the players' names and country. 4. Which three countries have won the most medals in recent years that's from 1992 to 2016? 5. Display the male gold medal winners of the 100-meters track and field sprint event over the years? 6. List the results starting with the most recent first and show the Olympic city, edition, athlete and the country they represent. 7. Plot the number of medals achieved by the US team, that's the men and women, in Rio de Janeiro 2016 using matplotlib and seaborn. Hint use sns.countplot function. 8. Is there any trend of the number of men and women over time? Use number men vs year; women vs year variables 9. Has the geographic representation changed over time? Hint check number of countries vs year 10. What are the proportions of women on Olympic teams in 2008 and 2016? ID,Name,Sex,Age,Height,Weight,Team,NOC,Games,Year,Season,City,Sport,Event,Medal 1724,Aristidis Akratopoulos,M,NA,NA,NA,Greece,GRE,1896 Summer,1896,Summer,Athina,Tennis,Tennis Men's Singles,NA 1724,Aristidis Akratopoulos,M,NA,NA,NA,Greece-3,GRE,1896 Summer,1896,Summer,Athina,Tennis,Tennis Men's Doubles,NA 1725,"Konstantinos ""Kostas"" Akratopoulos",M,NA,NA,NA,Greece,GRE,1896 Summer,1896,Summer,Athina,Tennis,Tennis Men's Singles,NA 1725,"Konstantinos ""Kostas"" Akratopoulos",M,NA,NA,NA,Greece-3,GRE,1896 Summer,1896,Summer,Athina,Tennis,Tennis Men's Doubles,NA 4113,Anastasios Andreou,M,NA,NA,NA,Greece,GRE,1896 Summer,1896,Summer,Athina,Athletics,Athletics Men's 110 metres Hurdles,NA 4116,Ioannis Andreou,M,NA,NA,NA,Greece,GRE,1896 Summer,1896,Summer,Athina,Swimming,"Swimming Men's 1,200 metres Freestyle",Silver 4189,Nikolaos Andriakopoulos,M,NA,NA,NA,Greece,GRE,1896 Summer,1896,Summer,Athina,Gymnastics,Gymnastics Men's Rope Climbing,Gold 4431,Georgios Anninos,M,NA,NA,NA,Greece,GRE,1896 Summer,1896,Summer,Athina,Swimming,Swimming Men's 100 metres Freestyle,NA 4493,Antelothanasis,M,NA,NA,NA,Greece,GRE,1896 Summer,1896,Summer,Athina,Shooting,"Shooting Men's Free Rifle, Three Positions, 300 metres",NA 5660,Georgios Aspiotis,M,NA,NA,NA,Greece,GRE,1896 Summer,1896,Summer,Athina,Cycling,"Cycling Men's Road Race, Individual",NA 8620,Edward Battel,M,NA,NA,NA,Great Britain,GBR,1896 Summer,1896,Summer,Athina,Cycling,"Cycling Men's Road Race, Individual",Bronze 8620,Edward Battel,M,NA,NA,NA,Great Britain,GBR,1896 Summer,1896,Summer,Athina,Cycling,Cycling Men's 333 metres Time Trial,NA 8620,Edward Battel,M,NA,NA,NA,Great Britain,GBR,1896 Summer,1896,Summer,Athina,Cycling,Cycling Men's 100 kilometres,NA 8747,Albert Baumann,M,NA,NA,NA,Switzerland,SUI,1896 Summer,1896,Summer,Athina,Shooting,"Shooting Men's Military Rifle, 200 metres",NA 9760,Spyridon Belokas,M,NA,NA,NA,Greece,GRE,1896 Summer,1896,Summer,Athina,Athletics,Athletics Men's Marathon,NA 12068,Arthur Charles Blake,M,24,NA,NA,United States,USA,1896 Summer,1896,Summer,Athina,Athletics,"Athletics Men's 1,500 metres",Silver 12068,Arthur Charles Blake,M,24,NA,NA,United States,USA,1896 Summer,1896,Summer,Athina,Athletics,Athletics Men's Marathon,NA 12563,Conrad Helmut Fritz Bcker,M,25,NA,NA,Germany,GER,1896 Summer,1896,Summer,Athina,Gymnastics,Gymnastics Men's Horse Vault,NA 12563,Conrad Helmut Fritz Bcker,M,25,NA,NA,Germany,GER,1896 Summer,1896,Summer,Athina,Gymnastics,Gymnastics Men's Parallel Bars,NA 12563,Conrad Helmut Fritz Bcker,M,25,NA,NA,Germany,GER,1896 Summer,1896,Summer,Athina,Gymnastics,"Gymnastics Men's Parallel Bars, Teams",Gold 12563,Conrad Helmut Fritz Bcker,M,25,NA,NA,Germany,GER,1896 Summer,1896,Summer,Athina,Gymnastics,Gymnastics Men's Horizontal Bar,NA 12563,Conrad Helmut Fritz Bcker,M,25,NA,NA,Germany,GER,1896 Summer,1896,Summer,Athina,Gymnastics,"Gymnastics Men's Horizontal Bar, Teams",Gold 12563,Conrad Helmut Fritz Bcker,M,25,NA,NA,Germany,GER,1896 Summer,1896,Summer,Athina,Gymnastics,Gymnastics Men's Rings,NA 12563,Conrad Helmut Fritz Bcker,M,25,NA,NA,Germany,GER,1896 Summer,1896,Summer,Athina,Gymnastics,Gymnastics Men's Pommelled Horse,NA 12929,John Mary Pius Boland,M,25,NA,NA,Great Britain,GBR,1896 Summer,1896,Summer,Athina,Tennis,Tennis Men's Singles,Gold 12929,John Mary Pius Boland,M,25,NA,NA,Great Britain/Germany,GBR,1896 Summer,1896,Summer,Athina,Tennis,Tennis Men's Doubles,Gold 16616,"Thomas Edmund ""Tom"" Burke",M,21,183,66,United States,USA,1896 Summer,1896,Summer,Athina,Athletics,Athletics Men's 100 metres,Gold 16616,"Thomas Edmund ""Tom"" Burke",M,21,183,66,United States,USA,1896 Summer,1896,Summer,Athina,Athletics,Athletics Men's 400 metres,Gold 17492,Eugne Henri Callot,M,20,NA,NA,France,FRA,1896 Summer,1896,Summer,Athina,Fencing,"Fencing Men's Foil, Individual",Silver 18785,Demetrius Emmanuel Casdagli,M,23,NA,NA,Greece,GRE,1896 Summer,1896,Summer,Athina,Tennis,Tennis Men's Singles,Silver 18785,Demetrius Emmanuel Casdagli,M,23,NA,NA,Greece-1,GRE,1896 Summer,1896,Summer,Athina,Tennis,Tennis Men's Doubles,Silver 19657,Charles Champaud,M,NA,NA,NA,Switzerland,SUI,1896 Summer,1896,Summer,Athina,Gymnastics,Gymnastics Men's Horse Vault,NA 19657,Charles Champaud,M,NA,NA,NA,Switzerland,SUI,1896 Summer,1896,Summer,Athina,Gymnastics,Gymnastics Men's Parallel Bars,NA 19657,Charles Champaud,M,NA,NA,NA,Switzerland,SUI,1896 Summer,1896,Summer,Athina,Gymnastics,Gymnastics Men's Pommelled Horse,NA 21795,Ellery Harding Clark,M,22,180,NA,United States,USA,1896 Summer,1896,Summer,Athina,Athletics,Athletics Men's High Jump,Gold 21795,Ellery Harding Clark,M,22,180,NA,United States,USA,1896 Summer,1896,Summer,Athina,Athletics,Athletics Men's Long Jump,Gold 21795,Ellery Harding Clark,M,22,180,NA,United States,USA,1896 Summer,1896,Summer,Athina,Athletics,Athletics Men's Shot Put,NA 22700,James Brendan Bennet Connolly,M,27,175,72,United States,USA,1896 Summer,1896,Summer,Athina,Athletics,Athletics Men's High Jump,Silver 22700,James Brendan Bennet Connolly,M,27,175,72,United States,USA,1896 Summer,1896,Summer,Athina,Athletics,Athletics Men's Long Jump,Bronze 22700,James Brendan Bennet Connolly,M,27,175,72,United States,USA,1896 Summer,1896,Summer,Athina,Athletics,Athletics Men's Triple Jump,Gold 24423,"Thomas Pelham ""Tom"" Curtis",M,23,176,66,United States,USA,1896 Summer,1896,Summer,Athina,Athletics,Athletics Men's 100 metres,NA 24423,"Thomas Pelham ""Tom"" Curtis",M,23,176,66,United States,USA,1896 Summer,1896,Summer,Athina,Athletics,Athletics Men's 110 metres Hurdles,Gold 25072,Evangelos Damaskos,M,NA,NA,NA,Greece,GRE,1896 Summer,1896,Summer,Athina,Athletics,Athletics Men's Pole Vault,Bronze 25184,Nndor Dni,M,24,NA,NA,Hungary,HUN,1896 Summer,1896,Summer,Athina,Athletics,Athletics Men's 800 metres,Silver 26280,Georges Daviel de la Nzire,M,17,NA,NA,France,FRA,1896 Summer,1896,Summer,Athina,Athletics,Athletics Men's 800 metres,NA 26315,Henri de Laborde,M,NA,NA,NA,France,FRA,1896 Summer,1896,Summer,Athina,Fencing,"Fencing Men's Foil, Individual",NA 26984,J. Defert,M,NA,NA,NA,France,FRA,1896 Summer,1896,Summer,Athina,Tennis,Tennis Men's Singles,NA 27318,Dimitrios Deligiannis,M,NA,185,106,Greece,GRE,1896 Summer,1896,Summer,Athina,Athletics,Athletics Men's Marathon,NA 28169,Georgios Diamantis,M,NA,NA,NA,Greece,GRE,1896 Summer,1896,Summer,Athina,Shooting,"Shooting Men's Free Rifle, Three Positions, 300 metres",NA 28169,Georgios Diamantis,M,NA,NA,NA,Greece,GRE,1896 Summer,1896,Summer,Athina,Shooting,"Shooting Men's Military Rifle, 200 metres",NA 29084,Kurt Wilhelm Doerry,M,21,179,73,Germany,GER,1896 Summer,1896,Summer,Athina,Athletics,Athletics Men's 100 metres,NA 29084,Kurt Wilhelm Doerry,M,21,179,73,Germany,GER,1896 Summer,1896,Summer,Athina,Athletics,Athletics Men's 400 metres,NA 29084,Kurt Wilhelm Doerry,M,21,179,73,Germany,GER,1896 Summer,1896,Summer,Athina,Athletics,Athletics Men's 110 metres Hurdles,NA 29467,Nikolaos Dorakis,M,NA,NA,NA,Greece,GRE,1896 Summer,1896,Summer,Athina,Shooting,"Shooting Men's Free Pistol, 30 metres",NA 29467,Nikolaos Dorakis,M,NA,NA,NA,Greece,GRE,1896 Summer,1896,Summer,Athina,Shooting,"Shooting Men's Military Pistol, 25 metres",Bronze 30049,Dimitrios Drivas,M,NA,NA,NA,Greece,GRE,1896 Summer,1896,Summer,Athina,Swimming,Swimming Men's 100 metres Freestyle For Sailors,Bronze 32330,Launceston Elliot,M,21,188,102,Great Britain,GBR,1896 Summer,1896,Summer,Athina,Athletics,Athletics Men's 100 metres,NA 32330,Launceston Elliot,M,21,188,102,Great Britain,GBR,1896 Summer,1896,Summer,Athina,Weightlifting,"Weightlifting Men's Unlimited, One Hand",Gold 32330,Launceston Elliot,M,21,188,102,Great Britain,GBR,1896 Summer,1896,Summer,Athina,Weightlifting,"Weightlifting Men's Unlimited, Two Hands",Silver 32330,Launceston Elliot,M,21,188,102,Great Britain,GBR,1896 Summer,1896,Summer,Athina,Wrestling,"Wrestling Men's Unlimited Class, Greco-Roman",NA 32330,Launceston Elliot,M,21,188,102,Great Britain,GBR,1896 Summer,1896,Summer,Athina,Gymnastics,Gymnastics Men's Rope Climbing,NA 35093,Alexios Fetsis,M,NA,NA,NA,Greece,GRE,1896 Summer,1896,Summer,Athina,Shooting,"Shooting Men's Free Rifle, Three Positions, 300 metres",NA 35093,Alexios Fetsis,M,NA,NA,NA,Greece,GRE,1896 Summer,1896,Summer,Athina,Shooting,"Shooting Men's Military Rifle, 200 metres",NA 35094,Angelos Fetsis,M,NA,NA,NA,Greece,GRE,1896 Summer,1896,Summer,Athina,Athletics,Athletics Men's 800 metres,NA 35094,Angelos Fetsis,M,NA,NA,NA,Greece,GRE,1896 Summer,1896,Summer,Athina,Athletics,"Athletics Men's 1,500 metres",NA 35698,"Edwin Harold ""Teddy"" Flack",M,22,NA,NA,Australia,AUS,1896 Summer,1896,Summer,Athina,Tennis,Tennis Men's Singles,NA 35698,"Edwin Harold ""Teddy"" Flack",M,22,NA,NA,Australia/Great Britain,AUS,1896 Summer,1896,Summer,Athina,Tennis,Tennis Men's Doubles,Bronze 35698,"Edwin Harold ""Teddy"" Flack",M,22,NA,NA,Australia,AUS,1896 Summer,1896,Summer,Athina,Athletics,Athletics Men's 800 metres,Gold 35698,"Edwin Harold ""Teddy"" Flack",M,22,NA,NA,Australia,AUS,1896 Summer,1896,Summer,Athina,Athletics,"Athletics Men's 1,500 metres",Gold 35698,"Edwin Harold ""Teddy"" Flack",M,22,NA,NA,Australia,AUS,1896 Summer,1896,Summer,Athina,Athletics,Athletics Men's Marathon,NA 35708,Marie Lon Flameng,M,18,NA,NA,France,FRA,1896 Summer,1896,Summer,Athina,Cycling,Cycling Men's Sprint,Bronze 35708,Marie Lon Flameng,M,18,NA,NA,France,FRA,1896 Summer,1896,Summer,Athina,Cycling,Cycling Men's 333 metres Time Trial,NA 35708,Marie Lon Flameng,M,18,NA,NA,France,FRA,1896 Summer,1896,Summer,Athina,Cycling,"Cycling Men's 10,000 metres",Silver 35708,Marie Lon Flameng,M,18,NA,NA,France,FRA,1896 Summer,1896,Summer,Athina,Cycling,Cycling Men's 100 kilometres,Gold 35740,Alfred Flatow,M,26,NA,NA,Germany,GER,1896 Summer,1896,Summer,Athina,Gymnastics,Gymnastics Men's
Answered 1 days AfterOct 13, 2021

Answer To: Homework 5 For this homework you are required to use Python (Spyder is recommended). Deadline: Now ~...

Vaibhav answered on Oct 15 2021
124 Votes
Assignment-Notebook.html


Olympics.csv s a historical dataset on the modern Olympic Games, including all the Games from Athens 1896 to Rio de Janeiro 2016. The olympics data set is posted on D2L, it contains a list of medallists at the Games of the Olympiad per edition, sport, discipline, gender and event.¶
Importing the libraries
In [1]:

import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sns
In [2]:

data = pd.read_csv('olympics2016.csv') # reading the data
In [3]:

data.head(5) # displaying the first 5 values and column names.
Out[3]:
                ID        Name        Sex        Age        Height        Weight        Team        NOC        Games        Year        Season        City        Sport        Event        Medal
        0        1724        Aristidis Akratopoulos        M        NaN        NaN        NaN        Greece        GRE        1896 Summer        1896        Summer        Athina        Tennis        Tennis Men's Singles        NaN
        1        1724        Aristidis Akratopoulos        M        NaN        NaN        NaN        Greece-3        GRE        1896 Summer        1896        Summer        Athina        Tennis        Tennis Men's Doubles        NaN
        2        1725        Konstantinos "Kostas" Akratopoulos        M        NaN        NaN        NaN        Greece        GRE        1896 Summer        1896        Summer        Athina        Tennis        Tennis Men's Singles        NaN
        3        1725        Konstantinos "Kostas" Akratopoulos        M        NaN        NaN        NaN        Greece-3        GRE        1896 Summer        1896        Summer        Athina        Tennis        Tennis Men's Doubles        NaN
        4        4113        Anastasios Andreou        M        NaN        NaN        NaN        Greece        GRE        1896 Summer        1896        Summer        Athina        Athletics        Athletics Men's 110 metres Hurdles        NaN
1.Which country has won the most female's gold medals in singles tennis over the years?¶
In [4]:

most_female_gold_tennis = data.loc[data.Event == "Tennis Women's Singles"].groupby('Team').count().sort_values(by='Medal', ascending=False).index[0]
print(most_female_gold_tennis)
United States
2. In which events did Jesse Owens win a medal?¶
In [5]:

Jesse_Owens_medals = data[data.Name.str.contains("\"Jesse\"")].Event.values
print(Jesse_Owens_medals)
["Athletics Men's 100 metres" "Athletics Men's 200 metres"
"Athletics Men's 4 x 100 metres Relay" "Athletics Men's Long Jump"
"Boxing Men's Welterweight" "Swimming Men's 200 metres Backstroke"
"Swimming Men's 400 metres Individual Medley"]
3. Sort the results alphabetically by the players' names and country.¶
In [6]:

sorted_data = data.sort_values(['Name', 'Team'])
sorted_data.head(10)
Out[6]:
                ID        Name        Sex        Age        Height        Weight        Team        NOC        Games        Year        Season        City        Sport        Event        Medal
        257547        869        Gabrielle Marie "Gabby" Adcock (White-)        F        25.0        167.0        NaN        Great Britain        GBR        2016 Summer        2016        Summer        Rio de Janeiro        Badminton        Badminton Mixed Doubles        NaN
        44863        107953        Eleonora Margarida Josephina Scmitt        F        16.0        NaN        NaN        Brazil        BRA        1948 Summer        1948        Summer        London        Swimming        Swimming Women's 100 metres Freestyle        NaN
        44864        107953        Eleonora Margarida Josephina Scmitt        F        16.0        NaN        NaN        Brazil        BRA        1948 Summer        1948        Summer        London        Swimming        Swimming Women's 4 x 100 metres Freestyle Relay        NaN
        9826        46661        Jean Hauptmanns        M        26.0        NaN        NaN        Germany        GER        1912 Summer        1912        Summer        Stockholm        Wrestling        Wrestling Men's Heavyweight, Greco-Roman        NaN
        40301        26388        Luis ngel Fernando de los Santos Grossi        M        23.0        NaN        NaN        
Uruguay        URU        1948 Summer        1948        Summer        London        Cycling        Cycling Men's Team Pursuit, 4,000 metres        NaN
        48012        26388        Luis ngel Fernando de los Santos Grossi        M        27.0        NaN        NaN        Uruguay        URU        1952 Summer        1952        Summer        Helsinki        Cycling        Cycling Men's Road Race, Individual        NaN
        48013        26388        Luis ngel Fernando de los Santos Grossi        M        27.0        NaN        NaN        Uruguay        URU        1952 Summer        1952        Summer        Helsinki        Cycling        Cycling Men's Road Race, Team        NaN
        48014        26388        Luis ngel Fernando de los Santos Grossi        M        27.0        NaN        NaN        Uruguay        URU        1952 Summer        1952        Summer        Helsinki        Cycling        Cycling Men's 1,000 metres Time Trial        NaN
        48015        26388        Luis ngel Fernando de los Santos Grossi        M        27.0        NaN        NaN        Uruguay        URU        1952 Summer        1952        Summer        Helsinki        Cycling        Cycling Men's Team Pursuit, 4,000 metres        NaN
        260535        29842        Th Anh        F        20.0        165.0        58.0        Vietnam        VIE        2016 Summer        2016        Summer        Rio de Janeiro        Fencing        Fencing Women's Foil, Individual        NaN
4. Which three countries have won the most medals in recent years that's from 1992 to 2016?¶
In [7]:

top_three = data.loc[(data.Year >= 1992) & (data.Medal.notna())].groupby('Team').agg('count').sort_values(by='Medal',ascending = False).head(3).index.values
print(top_three)
['United States' 'Germany' 'Russia']
5. Display the male gold medal winners of the 100-meters track and field sprint event over the years?¶
In [8]:

male_gold_medal_100m = data.loc[(data.Event == "Athletics Men's 100 metres") &(data.Medal == 'Gold')].Name.unique()
print(male_gold_medal_100m)
['Thomas Edmund "Tom" Burke' 'Frank Washington Jarvis'
'Charles Archibald "Archie" Hahn' 'Reginald Edgar "Reggie" Walker'
'Ralph Cook Craig' 'Charles William "Charley" Paddock'
'Harold Maurice Abrahams' 'Percy Alfred Williams'
'Thomas Edward "Eddie" Tolan, Jr.' 'James Cleveland "Jesse" Owens'
'William Harrison Dillard' 'Lindy John Remigino' 'Bobby Joe Morrow'
'Armin Hary' 'Robert Lee "Bob" Hayes' 'James Ray "Jim" Hines'
'Valeriy Pylypovych Borzov' 'Hasely Joachim Crawford'
'Allan Wipper Wells' 'Frederick Carlton "Carl" Lewis'
'Linford Ecerio Christie' 'Donovan Bailey' 'Maurice Greene'
'Justin Alexander Gatlin' 'Usain St. Leo Bolt']
6. List the results starting with the most recent first and show the Olympic city, edition, athlete and the country they represent.¶
In [9]:

data.sort_values(by='Year', ascending= False)[["City", "Games", "Name","Team"]].reset_index(drop='True')
Out[9]:
                City        Games        Name        Team
        0        Rio de Janeiro        2016 Summer        Olga Igorevna Zyuzkova        Belarus
        1        Rio de Janeiro        2016 Summer        Anna Hahner        Germany
        2        Rio de Janeiro        2016 Summer        Daniah Hagul        Libya
        3        Rio de Janeiro        2016 Summer        Nathalie Mari Hagman        Sweden
        4        Rio de Janeiro        2016 Summer        Kosuke Hagino        Japan
        ...        ...        ...        ...        ...
        271111        Athina        1896 Summer        Pavlos Pavlidis        Greece
        271112        Athina        1896 Summer        Pavlos Pavlidis        Greece
        271113        Athina        1896 Summer        Pavlos Pavlidis        Greece
        271114        Athina        1896 Summer        Antonios Pepanos        Greece
        271115        Athina        1896 Summer        Aristidis Akratopoulos        Greece
271116 rows × 4 columns
7. Plot the number of medals achieved by the US team, that's the men and women, in Rio de Janeiro 2016 using matplotlib and seaborn. Hint use sns.countplot function.¶
In [10]:

US_medals = data.loc[(data.City == "Rio de Janeiro") & (data.Team == 'United States')].dropna()
sns.countplot(x=US_medals.Sex,hue=US_medals.Medal, data = US_medals)
Out[10]:

8. Is there any trend of the number of men and women over time? Use number men vs year; women vs year variables¶
In [11]:

plt.xlabel('Year')
plt.ylabel('Total Men')
plt.plot(data.loc[data.Sex == 'M'].groupby('Year').count()['ID'], label='Men')
plt.plot(data.loc[data.Sex == 'F'].groupby('Year').count()['ID'], label='Women')
plt.legend()
plt.show()
9. Has the geographic representation changed over time? Hint check number of countries vs year¶
In [12]:

years = data.groupby('Year').apply(lambda x: len(x.Team.unique()))
In [13]:

plt.xlabel('')
plt.plot(data.groupby('Year').apply(lambda x: len(x.Team.unique())))
plt.show()
10. What are the proportions of women on Olympic teams in 2008 and 2016?¶
In [14]:

women_2008 = data.loc[(data.Year == 2008) & (data.Sex == 'F')].shape[0] / data.loc[(data.Year == 2008)].shape[0]
women_2012 = data.loc[(data.Year == 2012) & (data.Sex == 'F')].shape[0] / data.loc[(data.Year == 2012)].shape[0]
print(str(women_2008*100)+ " percent\n", str(women_2012*100) + " percent")
42.758417879723574 percent
45.00773993808049 percent
Assignment-Notebook.ipynb
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Olympics.csv s a historical dataset on the modern Olympic Games, including all the Games from Athens 1896 to Rio de Janeiro 2016. The olympics data set is posted on D2L, it contains a list of medallists at the Games of the Olympiad per edition, sport, discipline, gender and event."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Importing the libraries"
]
},
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [],
"source": [
"import numpy as np\n",
"import pandas as pd\n",
"import matplotlib.pyplot as plt\n",
"import seaborn as sns"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [],
"source": [
"data = pd.read_csv('olympics2016.csv') # reading the data"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"
\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"
IDNameSexAgeHeightWeightTeamNOCGamesYearSeasonCitySportEventMedal
01724Aristidis AkratopoulosMNaNNaNNaNGreeceGRE1896 Summer1896SummerAthinaTennisTennis Men's SinglesNaN
11724Aristidis AkratopoulosMNaNNaNNaNGreece-3GRE1896 Summer1896SummerAthinaTennisTennis Men's DoublesNaN
21725Konstantinos \"Kostas\" AkratopoulosMNaNNaNNaNGreeceGRE1896 Summer1896SummerAthinaTennisTennis Men's SinglesNaN
31725Konstantinos \"Kostas\" AkratopoulosMNaNNaNNaNGreece-3GRE1896 Summer1896SummerAthinaTennisTennis Men's DoublesNaN
44113Anastasios AndreouMNaNNaNNaNGreeceGRE1896 Summer1896SummerAthinaAthleticsAthletics Men's 110 metres HurdlesNaN
\n",
"
"
],
"text/plain": [
" ID Name Sex Age Height Weight \\\n",
"0 1724 Aristidis Akratopoulos M NaN NaN NaN \n",
"1 1724 Aristidis Akratopoulos M NaN NaN NaN \n",
"2 1725 Konstantinos \"Kostas\" Akratopoulos M NaN NaN NaN \n",
"3 1725 Konstantinos \"Kostas\" Akratopoulos M NaN NaN NaN \n",
"4 4113 Anastasios Andreou M NaN NaN NaN \n",
"\n",
" Team NOC Games Year Season City Sport \\\n",
"0 Greece GRE 1896 Summer 1896 Summer Athina Tennis \n",
"1 Greece-3 GRE 1896 Summer 1896 Summer Athina Tennis \n",
"2 Greece GRE 1896 Summer 1896 Summer Athina Tennis \n",
"3 Greece-3 GRE 1896 Summer 1896 Summer Athina Tennis \n",
"4 Greece GRE 1896 Summer 1896 Summer Athina Athletics \n",
"\n",
" Event Medal \n",
"0 Tennis Men's Singles NaN \n",
"1 Tennis Men's Doubles NaN \n",
"2 Tennis Men's Singles NaN \n",
"3 Tennis Men's Doubles NaN \n",
"4 Athletics Men's 110 metres Hurdles NaN "
]
},
"execution_count": 3,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"data.head(5) # displaying the first 5 values and column names."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### 1.Which country has won the most female's gold medals in singles tennis over the years? "
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"United States\n"
]
}
],
"source": [
"most_female_gold_tennis = data.loc[data.Event == \"Tennis Women's Singles\"].groupby('Team').count().sort_values(by='Medal', ascending=False).index[0]\n",
"print(most_female_gold_tennis)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### 2. In which events did Jesse Owens win a medal? "
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"[\"Athletics Men's 100 metres\" \"Athletics Men's 200 metres\"\n",
" \"Athletics Men's 4 x 100 metres Relay\" \"Athletics Men's Long Jump\"\n",
" \"Boxing Men's Welterweight\" \"Swimming Men's 200 metres Backstroke\"\n",
" \"Swimming Men's 400 metres Individual Medley\"]\n"
]
}
],
"source": [
"Jesse_Owens_medals = data[data.Name.str.contains(\"\\\"Jesse\\\"\")].Event.values\n",
"print(Jesse_Owens_medals)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### 3. Sort the results alphabetically by the players' names and country."
]
},
{
"cell_type": "code",
"execution_count": 6,
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"
\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"
IDNameSexAgeHeightWeightTeamNOCGamesYearSeasonCitySportEventMedal
257547869Gabrielle Marie \"Gabby\" Adcock (White-)F25.0167.0NaNGreat BritainGBR2016 Summer2016SummerRio de JaneiroBadmintonBadminton Mixed DoublesNaN
44863107953Eleonora Margarida Josephina ScmittF16.0NaNNaNBrazilBRA1948 Summer1948SummerLondonSwimmingSwimming Women's 100 metres FreestyleNaN
44864107953Eleonora Margarida Josephina ScmittF16.0NaNNaNBrazilBRA1948 Summer1948SummerLondonSwimmingSwimming Women's 4 x 100 metres Freestyle RelayNaN
982646661Jean HauptmannsM26.0NaNNaNGermanyGER1912 Summer1912SummerStockholmWrestlingWrestling Men's Heavyweight, Greco-RomanNaN
4030126388Luis ngel Fernando de los Santos GrossiM23.0NaNNaNUruguayURU1948 Summer1948SummerLondonCyclingCycling Men's Team Pursuit, 4,000 metresNaN
4801226388Luis ngel Fernando de los Santos GrossiM27.0NaNNaNUruguayURU1952 Summer1952SummerHelsinkiCyclingCycling Men's Road Race, IndividualNaN
4801326388Luis ngel Fernando de los Santos GrossiM27.0NaNNaNUruguayURU1952 Summer1952SummerHelsinkiCyclingCycling Men's Road Race, TeamNaN
4801426388Luis ngel Fernando de los Santos GrossiM27.0NaNNaNUruguayURU1952 Summer1952SummerHelsinkiCyclingCycling Men's 1,000 metres Time TrialNaN
4801526388Luis ngel Fernando de los Santos GrossiM27.0NaNNaNUruguayURU1952 Summer1952SummerHelsinkiCyclingCycling Men's Team Pursuit, 4,000 metresNaN
26053529842Th AnhF20.0165.058.0VietnamVIE2016 Summer2016SummerRio de JaneiroFencingFencing Women's Foil, IndividualNaN
\n",
"
"
],
"text/plain": [
" ID Name Sex Age Height \\\n",
"257547 869 Gabrielle Marie \"Gabby\" Adcock (White-) F 25.0 167.0 \n",
"44863 107953 Eleonora Margarida Josephina Scmitt F 16.0 NaN \n",
"44864 107953 Eleonora Margarida Josephina Scmitt F 16.0 NaN \n",
"9826 46661 Jean Hauptmanns M 26.0 NaN \n",
"40301 26388 Luis ngel Fernando de los Santos Grossi M 23.0 NaN \n",
"48012 26388 Luis ngel Fernando de los Santos Grossi M 27.0 NaN \n",
"48013 26388 Luis ngel Fernando de los Santos Grossi M 27.0 NaN \n",
"48014 26388 Luis ngel Fernando de los Santos Grossi M 27.0 NaN \n",
"48015 26388 Luis ngel Fernando de los Santos Grossi M 27.0 NaN \n",
"260535 29842 Th Anh F 20.0 165.0 \n",
"\n",
" Weight Team NOC Games Year Season City \\\n",
"257547 NaN Great Britain GBR 2016 Summer 2016 Summer Rio de Janeiro \n",
"44863 NaN Brazil BRA 1948 Summer 1948 Summer London \n",
"44864 NaN Brazil BRA 1948 Summer 1948 Summer London \n",
"9826 NaN Germany GER 1912 Summer 1912 Summer Stockholm \n",
"40301 NaN Uruguay URU 1948 Summer 1948 Summer London \n",
"48012 NaN Uruguay URU 1952 Summer 1952 Summer Helsinki \n",
"48013 NaN Uruguay URU 1952 Summer 1952 Summer Helsinki \n",
"48014 NaN Uruguay URU 1952 Summer 1952 Summer Helsinki \n",
"48015 NaN Uruguay URU 1952 Summer 1952 Summer Helsinki \n",
"260535 58.0 Vietnam VIE 2016 Summer 2016 Summer Rio de Janeiro \n",
"\n",
" Sport Event Medal \n",
"257547 Badminton Badminton Mixed Doubles NaN \n",
"44863 Swimming Swimming Women's 100 metres Freestyle NaN \n",
"44864 Swimming Swimming Women's 4 x 100 metres Freestyle Relay NaN \n",
"9826 Wrestling Wrestling Men's Heavyweight, Greco-Roman NaN \n",
"40301 Cycling Cycling Men's Team Pursuit, 4,000 metres NaN \n",
"48012 Cycling Cycling Men's Road Race, Individual NaN \n",
"48013 Cycling Cycling Men's Road Race, Team NaN \n",
"48014 Cycling Cycling Men's 1,000 metres Time Trial NaN \n",
"48015 Cycling Cycling Men's Team Pursuit, 4,000 metres NaN \n",
"260535 Fencing Fencing Women's Foil, Individual NaN "
]
},
"execution_count": 6,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"sorted_data = data.sort_values(['Name', 'Team'])\n",
"sorted_data.head(10)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### 4. Which three countries have won the most medals in recent years that's from 1992 to 2016? "
]
},
{
"cell_type": "code",
"execution_count": 7,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"['United States' 'Germany' 'Russia']\n"
]
}
],
"source": [
"top_three = data.loc[(data.Year >= 1992) & (data.Medal.notna())].groupby('Team').agg('count').sort_values(by='Medal',ascending = False).head(3).index.values\n",
"print(top_three)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### 5. Display the male gold medal winners of the 100-meters track and field sprint event over the years?"
]
},
{
"cell_type": "code",
"execution_count": 8,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"['Thomas Edmund \"Tom\" Burke' 'Frank Washington Jarvis'\n",
" 'Charles Archibald \"Archie\" Hahn' 'Reginald Edgar \"Reggie\" Walker'\n",
" 'Ralph Cook Craig' 'Charles William \"Charley\" Paddock'\n",
" 'Harold Maurice Abrahams' 'Percy Alfred Williams'\n",
" 'Thomas Edward \"Eddie\" Tolan, Jr.' 'James Cleveland \"Jesse\" Owens'\n",
" 'William Harrison Dillard' 'Lindy John Remigino' 'Bobby Joe Morrow'\n",
" 'Armin Hary' 'Robert Lee \"Bob\" Hayes' 'James Ray \"Jim\" Hines'\n",
" 'Valeriy Pylypovych Borzov' 'Hasely Joachim Crawford'\n",
" 'Allan Wipper Wells' 'Frederick Carlton \"Carl\" Lewis'\n",
" 'Linford Ecerio Christie' 'Donovan Bailey' 'Maurice Greene'\n",
" 'Justin Alexander Gatlin' 'Usain St. Leo Bolt']\n"
]
}
],
"source": [
"male_gold_medal_100m = data.loc[(data.Event == \"Athletics Men's 100 metres\") &(data.Medal == 'Gold')].Name.unique()\n",
"print(male_gold_medal_100m)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### 6. List the results starting with the most recent first and show the Olympic city, edition, athlete and the country they represent. "
]
},
{
"cell_type": "code",
"execution_count": 9,
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"
\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"...
SOLUTION.PDF

Answer To This Question Is Available To Download

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here
CityGamesNameTeam
0Rio de Janeiro2016 SummerOlga Igorevna ZyuzkovaBelarus
1Rio de Janeiro2016 SummerAnna HahnerGermany
2Rio de Janeiro2016 SummerDaniah HagulLibya
3Rio de Janeiro2016 SummerNathalie Mari HagmanSweden
4Rio de Janeiro2016 SummerKosuke HaginoJapan
...............