Contact
CoCalc Logo Icon
StoreFeaturesDocsShareSupport News AboutSign UpSign In
| Download
Project: DS
Views: 186
Kernel: SageMath (stable)
import pandas as pd
data = pd.read_csv('athlete_events.csv') data.head()
ID Name Sex Age Height Weight Team NOC Games Year Season City Sport Event Medal
0 1 A Dijiang M 24.0 180.0 80.0 China CHN 1992 Summer 1992 Summer Barcelona Basketball Basketball Men's Basketball NaN
1 2 A Lamusi M 23.0 170.0 60.0 China CHN 2012 Summer 2012 Summer London Judo Judo Men's Extra-Lightweight NaN
2 3 Gunnar Nielsen Aaby M 24.0 NaN NaN Denmark DEN 1920 Summer 1920 Summer Antwerpen Football Football Men's Football NaN
3 4 Edgar Lindenau Aabye M 34.0 NaN NaN Denmark/Sweden DEN 1900 Summer 1900 Summer Paris Tug-Of-War Tug-Of-War Men's Tug-Of-War Gold
4 5 Christine Jacoba Aaftink F 21.0 185.0 82.0 Netherlands NED 1988 Winter 1988 Winter Calgary Speed Skating Speed Skating Women's 500 metres NaN

1. How old were the youngest male and female participants of the 1996 Olympics?

  • 16 and 15

  • 14 and 12

  • 16 and 12

  • 13 and 11

data[(data['Sex'] == 'M') & (data['Games'] == '1996 Summer')]['Age'].min(), data[(data['Sex'] == 'F') & (data['Games'] == '1996 Summer')]['Age'].min()
(14.0, 12.0)

2. What was the percentage of male gymnasts among all the male participants of the 2000 Olympics? Consider only Gymnastics as a target sport. Round the answer to the first decimal.

Hint: here and further if needed drop duplicated sportsmen to count only unique ones.

  • 0.2

  • 1.5

  • 2.5

  • 7.7

round(float(data[(data['Sport']=='Gymnastics') & (data['Sex'] == 'M') & (data['Games'] == '2000 Summer')]['Name'].nunique())/ float(data[(data['Sex'] == 'M') & (data['Games'] == '2000 Summer')]['Name'].nunique())*100, 1)
1.5

3. What are the mean and standard deviation of height for female basketball players participated in the 2000 Olympics? Round the answer to the first decimal.

  • 178.5 and 7.2

  • 179.4 and 10

  • 180.7 and 6.7

  • 182.4 and 9.1

data[(data['Sex']=='F') & (data['Sport']=='Basketball') & (data['Games'] == '2000 Summer')]['Height'].describe()
count 142.000000 mean 182.387324 std 9.139462 min 162.000000 25% 175.000000 50% 182.000000 75% 190.000000 max 213.000000 Name: Height, dtype: float64

4. Find a sportsperson participated in the 2002 Olympics, with the highest weight among other participants of the same Olympics. What sport did he or she do?

  • Judo

  • Bobsleigh

  • Weightlifting

  • Boxing

data[data['Games'] == '2002 Winter']['Weight'].describe()
count 4062.000000 mean 71.197070 std 13.257178 min 42.000000 25% 61.000000 50% 69.000000 75% 80.000000 max 123.000000 Name: Weight, dtype: float64
data[(data['Games'] == '2002 Winter') & (data['Weight'] == 123)]
ID Name Sex Age Height Weight Team NOC Games Year Season City Sport Event Medal
99154 50171 Emmanuel Hostache M 26.0 190.0 123.0 France FRA 2002 Winter 2002 Winter Salt Lake City Bobsleigh Bobsleigh Men's Two NaN

5. How many times did Pawe Abratkiewicz participate in the Olympics held in different years?

  • 0

  • 1

  • 2

  • 3

data[data['Name'] == 'Pawe Abratkiewicz']['Games'].nunique()
3

6. How many silver medals in tennis did sportspeople from the Australia team win at the 2000 Olympics? Count every medal from every sportsperson.

  • 0

  • 1

  • 2

  • 3

data[(data['Sport']=='Tennis') & (data['Games'] == '2000 Summer') & (data['Medal'] =='Silver') & (data['Team'] == 'Australia')]
ID Name Sex Age Height Weight Team NOC Games Year Season City Sport Event Medal
262820 131504 Todd Andrew Woodbridge M 29.0 178.0 75.0 Australia AUS 2000 Summer 2000 Summer Sydney Tennis Tennis Men's Doubles Silver
262831 131511 Mark Raymond Woodforde M 34.0 183.0 80.0 Australia AUS 2000 Summer 2000 Summer Sydney Tennis Tennis Men's Doubles Silver

7. Is it true that Switzerland won fewer medals than Serbia at the 2016 Olympics? Do not consider NaN values in Medal column.

  • Yes

  • No

ds = data[(data['Team'].isin(['Serbia', 'Switzerland'])) & (data['Games'] =='2016 Summer') & (data['Medal'].isin(['Gold', 'Silver', 'Bronze']))]
ds
WARNING: Some output was deleted.
ds.groupby('Team')['Medal'].describe()
count unique top freq
Team
Serbia 54 3 Silver 27
Switzerland 11 3 Gold 6

8. What age category did the fewest and the most participants of the 2014 Olympics belong to?

  • [45-55] and [25-35) correspondingly

  • [45-55] and [15-25) correspondingly

  • [35-45] and [25-35) correspondingly

  • [45-55] and [35-45) correspondingly

data[(data['Year']==2014) & (data['Age']>=45) & (data['Age']<=55)]['Name'].nunique(), data[(data['Year']==2014) & (data['Age']>=35) & (data['Age']<=45)]['Name'].nunique()
(5, 266)
data[(data['Year']==2014) & (data['Age']>=25) & (data['Age']<35)]['Name'].nunique(), data[(data['Year']==2014) & (data['Age']>=15) & (data['Age']<25)]['Name'].nunique(), data[(data['Year']==2014) & (data['Age']>=35) & (data['Age']<45)]['Name'].nunique()
(1397, 1193, 150)

9. Is it true that there were Summer Olympics held in Lake Placid? Is it true that there were Winter Olympics held in Sankt Moritz?

  • Yes, Yes

  • Yes, No

  • No, Yes

  • No, No

data[(data['Season'] == 'Summer') & (data['City'].str.startswith('Lake Placid'))].describe()
ID Age Height Weight Year
count 0.0 0.0 0.0 0.0 0.0
mean NaN NaN NaN NaN NaN
std NaN NaN NaN NaN NaN
min NaN NaN NaN NaN NaN
25% NaN NaN NaN NaN NaN
50% NaN NaN NaN NaN NaN
75% NaN NaN NaN NaN NaN
max NaN NaN NaN NaN NaN
data[(data['Season'] == 'Winter') & (data['City'].str.startswith('Sankt Moritz'))].describe()
ID Age Height Weight Year
count 1657.000000 1563.000000 238.000000 159.000000 1657.000000
mean 65513.748944 26.346769 173.155462 69.471698 1940.975256
std 37235.901480 5.827111 7.499437 8.586722 9.550020
min 529.000000 15.000000 155.000000 45.000000 1928.000000
25% 32961.000000 22.000000 168.000000 65.000000 1928.000000
50% 63990.000000 26.000000 173.000000 71.000000 1948.000000
75% 97263.000000 29.000000 178.000000 74.000000 1948.000000
max 135466.000000 54.000000 211.000000 103.000000 1948.000000

10. What is the absolute difference between the number of unique sports at the 1996 Olympics and 2016 Olympics?

  • 3

  • 10

  • 27

  • 34

data[(data['Year'] == 1996)]['Sport'].nunique(), data[(data['Year'] == 2016)]['Sport'].nunique()
(31, 34)