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
52 changes: 33 additions & 19 deletions build.py
Original file line number Diff line number Diff line change
@@ -1,35 +1,49 @@
import pandas as pd

import re

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

df = pd.read_csv('files/olympics.csv',header=1)

tp = df.columns.values
df.rename(columns=lambda x: re.sub('01 !','Gold',x),inplace=True)
df.rename(columns=lambda x: re.sub('02 !','Silver',x),inplace=True)
df.rename(columns=lambda x: re.sub('03 !','Bronze',x),inplace=True)
tp = list(df.index.values)
names = []
codes = []
for ele in tp:
names.append(ele.split('\xc2\xa0')[0])
#codes.append(ele.split('\xc2\xa0')[1])
df.index = names
df = df[:len(df)-1]
return df

def first_country(df):
"""
Enter your code here
"""
return df.iloc[0]


def gold_medal(df):
"""
Enter your code here
"""
pos = df['Gold'].idxmax()
return pos


def biggest_difference_in_gold_medal(df):
"""
Enter your code here
"""
print df
smr = df['Gold']
wint = df['Gold.1']
diff = smr-wint
pos = diff.idxmax()
return pos

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


df['Points'] = (df['Gold.2']*3 + df['Silver.2']*2 +df['Bronze.2'])
return df['Points']

load_data()
first_country(load_data())
gold_medal(load_data())
biggest_difference_in_gold_medal(load_data())
get_points(load_data())
# df = load_data()
# print(first_country(df)["# Summer"])
# print(gold_medal(df))
Expand Down
Binary file added build.pyc
Binary file not shown.
4 changes: 2 additions & 2 deletions files/olympics.csv
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15
,# Summer,01 !,02 !,03 !,Total,# Winter,01 !,02 !,03 !,Total,# Games,01 !,02 !,03 !,Combined total
0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,
# Summer,01 !,02 !,03 !,Total,# Winter,01 !,02 !,03 !,Total,# Games,01 !,02 !,03 !,Combined total
Afghanistan (AFG),13,0,0,2,2,0,0,0,0,0,13,0,0,2,2
Algeria (ALG),12,5,2,8,15,3,0,0,0,0,15,5,2,8,15
Argentina (ARG),23,18,24,28,70,18,0,0,0,0,41,18,24,28,70
Expand Down
Binary file added tests/__init__.pyc
Binary file not shown.
Binary file added tests/test_load_data.pyc
Binary file not shown.