Introduction to Data Science in Python
第 2 周 Assignment
记录下问题和自己的答案
Part 1
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. Use this dataset to answer the questions below.
Question 1
Which country has won the most gold medals in summer games?
This function should return a single string value.
【IN】
def answer_one():
return df[df['Gold'] == df['Gold'].max()].index[0]
answer_one()
【OUT】
'United States'
Question 2
Which country had the biggest difference between their summer and winter gold medal counts?
This function should return a single string value.
【IN】
def answer_two():
df['diff'] = abs(df['Gold'] - df['Gold.1'])
max = df['diff'].max()
return df[df['diff'] == max].index[0]
answer_two()
【OUT】
'United States'
Question 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?
S u m m e r G o l d − W i n t e r G o l d T o t a l G o l d \frac{Summer~Gold - Winter~Gold}{Total~Gold} Total GoldSummer Gold−Winter