Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,4 @@ Which country had the biggest difference between their summer and winter gold me
Write a function to update the dataframe to include a new column called "Points" for Games which is a weighted value where each gold medal counts for 3 points, silver medals for 2 points, and bronze
medals for 1 point. The function should return only the column (a Series object) which you created.
* Create a function get_points.
* Return dataframe with points column and index.
* Return dataframe with points column and index.
45 changes: 20 additions & 25 deletions build.py
Original file line number Diff line number Diff line change
@@ -1,37 +1,32 @@
import pandas as pd

import re

def load_data():
"""
Enter your code here
"""

olympics=pd.read_csv('files/olympics.csv',skiprows=1)
olympics.rename(columns={'Unnamed: 0':'Country_name'},inplace= True)
for i in olympics.columns:
if bool(re.match(".*01 !.*",i)):
olympics.rename(columns={i:re.sub('01 !','Gold',i)},inplace=True)
elif bool(re.match(".*02 !.*",i)):
olympics.rename(columns={i:re.sub('02 !','Silver',i)},inplace=True)
elif bool(re.match(".*03 !.*",i)):
olympics.rename(columns={i:re.sub('03 !','Bronze',i)},inplace=True)
olympics['Country_name']=olympics['Country_name'].apply(lambda x:x.split("\xc2\xa0")[0])
olympics.index=olympics['Country_name']
olympics=olympics[olympics.Country_name != "Totals"]
return olympics

def first_country(df):
"""
Enter your code here
"""

return df.iloc[0,:]

def gold_medal(df):
"""
Enter your code here
"""
return df['Country_name'][df['Gold.2']==df['Gold.2'].max()][0]


def biggest_difference_in_gold_medal(df):
"""
Enter your code here
"""

return df['Country_name'][abs(df['Total']-df['Total.1'])==abs(df['Total']-df['Total.1']).max()][0]
def get_points(df):
"""
Enter your code here
"""


# df = load_data()
# print(first_country(df)["# Summer"])
# print(gold_medal(df))
# print(biggest_difference_in_gold_medal(df))
# print(get_points(df))
df['points'] = (df['Gold.2']*3+df['Silver.2']*2+df['Bronze.2'])
return df['points']
print biggest_difference_in_gold_medal(load_data())
Binary file added build.pyc
Binary file not shown.
Binary file added tests/__init__.pyc
Binary file not shown.
Binary file added tests/test_load_data.pyc
Binary file not shown.