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
29 changes: 20 additions & 9 deletions build.py
Original file line number Diff line number Diff line change
@@ -1,37 +1,48 @@
import pandas as pd

import re
import numpy as np

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

df = pd.read_csv('./files/olympics.csv', skiprows=1)
df.rename(columns = {'01 !':'Gold', '02 !':'Silver', '03 !':'Bronze',
'01 !.1':'Gold_w', '02 !.1':'Silver_w', '03 !.1':'Bronze_w',
'01 !.2':'Gold_g', '02 !.2':'Silver_g', '03 !.2':'Bronze_g'}, inplace=True)
df.set_index(df['Unnamed: 0'].apply(lambda x: re.sub(r'\xc2\xa0\(.*', '',x)), inplace=True)
df.drop(['Unnamed: 0'], inplace=True, axis=1)
df.drop(['Totals'], inplace=True, axis=0)
return df

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

return df.iloc[0]

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

return df['Gold'].idxmax()

def biggest_difference_in_gold_medal(df):
"""
Enter your code here
"""
df['diff'] = np.absolute(df.Gold - df.Gold_w)
return df['diff'].idxmax()

def get_points(df):
"""
Enter your code here
"""
df['Points'] = df.apply(lambda x: (x['Gold_g'] * 3) + (x['Silver_g'] * 2) + (x['Bronze_g'] * 1), axis = 1)
return df['Points']


# df = load_data()
# print(first_country(df)["# Summer"])
# print(gold_medal(df))
# print(biggest_difference_in_gold_medal(df))
df = load_data()
print(first_country(df)["# Summer"])
print(gold_medal(df))
print(biggest_difference_in_gold_medal(df))
# print(get_points(df))
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.