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
Binary file modified __pycache__/__init__.cpython-36.pyc
Binary file not shown.
Binary file modified q01_load_data/__pycache__/__init__.cpython-36.pyc
Binary file not shown.
Binary file modified q01_load_data/__pycache__/build.cpython-36.pyc
Binary file not shown.
14 changes: 13 additions & 1 deletion q01_load_data/build.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,22 @@
# %load q01_load_data/build.py
import pandas as pd
import numpy as np
from sklearn.model_selection import train_test_split


def q01_load_data(path):
"write your solution here"
'write your solution here'
# use .read_csv function to read the
# data and header=0 to skip the first row
df = pd.read_csv(path, header=0)
new_header = df.iloc[0] # grab the first row for the header
new_header[0] = 'country name'
df = df[1:] # take the data less the header row
df.columns = new_header # set the header row as the df header
return df


path = 'data/olympics.csv'
q01_load_data(path)


Binary file modified q01_load_data/tests/__pycache__/__init__.cpython-36.pyc
Binary file not shown.
Binary file modified q01_load_data/tests/__pycache__/test.cpython-36.pyc
Binary file not shown.
Binary file modified q02_rename_columns/__pycache__/__init__.cpython-36.pyc
Binary file not shown.
Binary file modified q02_rename_columns/__pycache__/build.cpython-36.pyc
Binary file not shown.
11 changes: 9 additions & 2 deletions q02_rename_columns/build.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,16 @@
# %load q02_rename_columns/build.py
import pandas as pd
import numpy as np
from sklearn.model_selection import train_test_split
from greyatomlib.olympics_project.q01_load_data.build import q01_load_data

def q02_rename_columns(path):
"write your solution here"
'write your solution here'
df = q01_load_data(path)

df.rename(columns={'01 !':'Gold','02 !':'Silver','03 !':'Bronze'},inplace=True)
return df

path='./data/olympics.csv'
q02_rename_columns(path)


Binary file modified q02_rename_columns/tests/__pycache__/__init__.cpython-36.pyc
Binary file not shown.
Binary file modified q02_rename_columns/tests/__pycache__/test.cpython-36.pyc
Binary file not shown.
Binary file modified q03_split_country/__pycache__/__init__.cpython-36.pyc
Binary file not shown.
Binary file modified q03_split_country/__pycache__/build.cpython-36.pyc
Binary file not shown.
16 changes: 13 additions & 3 deletions q03_split_country/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,19 @@
import numpy as np
from sklearn.model_selection import train_test_split
from greyatomlib.olympics_project.q02_rename_columns.build import q02_rename_columns

import re

def q03_summer_gold_medals(path):
"write your solution here"
'write your solution here'
df = q02_rename_columns(path)

#tmp= df['country name'].apply(lambda x: re.findall('\((.*?)\)',x))
df['country name']=df['country name'].str.replace(r'\(([A-Za-z0-9 _]+)\)', '')
df['country name']=df['country name'].str.replace(r'\[([A-Za-z0-9_]+)\]', '')
df.index=df['country name']
df.drop(['country name','Totals'], axis=1,inplace=True)

return df[:-1]

path='./data/olympics.csv'
q03_summer_gold_medals(path)

Binary file modified q03_split_country/tests/__pycache__/__init__.cpython-36.pyc
Binary file not shown.
Binary file modified q03_split_country/tests/__pycache__/test.cpython-36.pyc
Binary file not shown.
Binary file not shown.
Binary file modified q04_country_with_most_gold_medals/__pycache__/build.cpython-36.pyc
Binary file not shown.
10 changes: 8 additions & 2 deletions q04_country_with_most_gold_medals/build.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,17 @@
# %load q04_country_with_most_gold_medals/build.py
import pandas as pd
import numpy as np
from sklearn.model_selection import train_test_split
from greyatomlib.olympics_project.q03_split_country.build import q03_summer_gold_medals


def q04_country_with_most_gold_medals(path):
"write your solution here"
'write your solution here'
df = q03_summer_gold_medals(path)

max_gold = df['Gold']
gold=pd.Series(max_gold.iloc[:,2].astype(np.int16))
return gold.idxmax().strip()


q04_country_with_most_gold_medals('./data/olympics.csv')

Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file modified q05_difference_in_gold_medal/__pycache__/build.cpython-36.pyc
Binary file not shown.
16 changes: 13 additions & 3 deletions q05_difference_in_gold_medal/build.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,19 @@
# %load q05_difference_in_gold_medal/build.py
import pandas as pd
import numpy as np
from sklearn.model_selection import train_test_split
from greyatomlib.olympics_project.q02_rename_columns.build import q02_rename_columns
import math

def q05_difference_in_gold_medal(path):
'write your solution here'
df= q02_rename_columns(path)
df=df[:-1]
df['bigg']= df['Gold'].iloc[:,0].astype(np.int16)-df['Gold'].iloc[:,1].astype(np.int16)
tmp=df['bigg']
#return df.loc[tmp.idxmax(),'country name'].strip()
return tmp.max()

q05_difference_in_gold_medal('./data/olympics.csv')

def q05_difference_in_gold_medal():
"write your solution here"


Binary file not shown.
Binary file not shown.
Binary file modified q06_get_points/__pycache__/__init__.cpython-36.pyc
Binary file not shown.
Binary file modified q06_get_points/__pycache__/build.cpython-36.pyc
Binary file not shown.
16 changes: 15 additions & 1 deletion q06_get_points/build.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,23 @@
# %load q06_get_points/build.py
import pandas as pd
import numpy as np
from sklearn.model_selection import train_test_split
from greyatomlib.olympics_project.q02_rename_columns.build import q02_rename_columns

path = "data/olympics.csv"
path = 'data/olympics.csv'


def q06_get_points(path):
df= q02_rename_columns(path)
g=df['Gold'].iloc[:,2].astype(np.int16)*3
b=df['Bronze'].iloc[:,2].astype(np.int16)*1
s=df['Silver'].iloc[:,2].astype(np.int16)*2
df['Points']=g+b+s
return df['Points']



q06_get_points(path)



Binary file modified q06_get_points/tests/__pycache__/__init__.cpython-36.pyc
Binary file not shown.
Binary file modified q06_get_points/tests/__pycache__/test.cpython-36.pyc
Binary file not shown.