diff --git a/README.md b/README.md index 3bc16ed..9adc00e 100644 --- a/README.md +++ b/README.md @@ -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. \ No newline at end of file +* Return dataframe with points column and index. diff --git a/build.py b/build.py index 7df5951..9aa6a61 100644 --- a/build.py +++ b/build.py @@ -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()) diff --git a/build.pyc b/build.pyc new file mode 100644 index 0000000..05b1ff6 Binary files /dev/null and b/build.pyc differ diff --git a/tests/__init__.pyc b/tests/__init__.pyc new file mode 100644 index 0000000..cf76b15 Binary files /dev/null and b/tests/__init__.pyc differ diff --git a/tests/test_load_data.pyc b/tests/test_load_data.pyc new file mode 100644 index 0000000..3b5c664 Binary files /dev/null and b/tests/test_load_data.pyc differ