diff --git a/__pycache__/__init__.cpython-36.pyc b/__pycache__/__init__.cpython-36.pyc new file mode 100644 index 0000000..f94a469 Binary files /dev/null and b/__pycache__/__init__.cpython-36.pyc differ diff --git a/q01_rename_columns/__pycache__/__init__.cpython-36.pyc b/q01_rename_columns/__pycache__/__init__.cpython-36.pyc index 86045c5..aae4b5c 100644 Binary files a/q01_rename_columns/__pycache__/__init__.cpython-36.pyc and b/q01_rename_columns/__pycache__/__init__.cpython-36.pyc differ diff --git a/q01_rename_columns/__pycache__/build.cpython-36.pyc b/q01_rename_columns/__pycache__/build.cpython-36.pyc index 56daa0d..48886f6 100644 Binary files a/q01_rename_columns/__pycache__/build.cpython-36.pyc and b/q01_rename_columns/__pycache__/build.cpython-36.pyc differ diff --git a/q01_rename_columns/build.py b/q01_rename_columns/build.py index 5d2373e..14ee4ad 100644 --- a/q01_rename_columns/build.py +++ b/q01_rename_columns/build.py @@ -1,5 +1,22 @@ +# %load q01_rename_columns/build.py # default imports import pandas as pd +def q01_rename_columns(path = './data/olympics.csv'): + data = pd.read_csv(path, skiprows=1) + data.rename(columns = {'Unnamed: 0' : 'Country', + 'Total':'Total_Summer', + 'Total.1':'Total_Winter', + 'Combined total':'Total', + '01 !':'Gold_Summer', + '02 !':'Silver_Summer', + '03 !':'Bronze_Summer', + '01 !.1':'Gold_Winter', + '02 !.1':'Silver_Winter', + '03 !.1':'Bronze_Winter', + '01 !.2':'Gold_Total', + '02 !.2':'Silver_Total', + '03 !.2':'Bronze_Total'}, inplace = True) + return data diff --git a/q01_rename_columns/tests/__pycache__/__init__.cpython-36.pyc b/q01_rename_columns/tests/__pycache__/__init__.cpython-36.pyc index ee14684..09b1e1a 100644 Binary files a/q01_rename_columns/tests/__pycache__/__init__.cpython-36.pyc and b/q01_rename_columns/tests/__pycache__/__init__.cpython-36.pyc differ diff --git a/q01_rename_columns/tests/__pycache__/test.cpython-36.pyc b/q01_rename_columns/tests/__pycache__/test.cpython-36.pyc index bd0596e..305af5f 100644 Binary files a/q01_rename_columns/tests/__pycache__/test.cpython-36.pyc and b/q01_rename_columns/tests/__pycache__/test.cpython-36.pyc differ diff --git a/q02_country_operations/__pycache__/__init__.cpython-36.pyc b/q02_country_operations/__pycache__/__init__.cpython-36.pyc index 005bbe0..0b21b41 100644 Binary files a/q02_country_operations/__pycache__/__init__.cpython-36.pyc and b/q02_country_operations/__pycache__/__init__.cpython-36.pyc differ diff --git a/q02_country_operations/__pycache__/build.cpython-36.pyc b/q02_country_operations/__pycache__/build.cpython-36.pyc index 65c7fed..86d5737 100644 Binary files a/q02_country_operations/__pycache__/build.cpython-36.pyc and b/q02_country_operations/__pycache__/build.cpython-36.pyc differ diff --git a/q02_country_operations/build.py b/q02_country_operations/build.py index d4c641d..65b0b8d 100644 --- a/q02_country_operations/build.py +++ b/q02_country_operations/build.py @@ -1,9 +1,14 @@ +# %load q02_country_operations/build.py # default imports from greyatomlib.olympics_project_new.q01_rename_columns.build import q01_rename_columns #Previous Functions -path = "./data/olympics.csv" -OlympicsDF=q01_rename_columns(path) +path = './data/olympics.csv' +OlympicsDF=q01_rename_columns(path) +def q02_country_operations(OlympicsDF): + country_col_new = OlympicsDF.Country.str.split(expand=True)[0] + OlympicsDF['Country_Name'] = country_col_new + return OlympicsDF diff --git a/q02_country_operations/tests/__pycache__/__init__.cpython-36.pyc b/q02_country_operations/tests/__pycache__/__init__.cpython-36.pyc index 3d1192a..730729f 100644 Binary files a/q02_country_operations/tests/__pycache__/__init__.cpython-36.pyc and b/q02_country_operations/tests/__pycache__/__init__.cpython-36.pyc differ diff --git a/q02_country_operations/tests/__pycache__/test.cpython-36.pyc b/q02_country_operations/tests/__pycache__/test.cpython-36.pyc index 1d77332..9c08edb 100644 Binary files a/q02_country_operations/tests/__pycache__/test.cpython-36.pyc and b/q02_country_operations/tests/__pycache__/test.cpython-36.pyc differ diff --git a/q03_better_event/__pycache__/__init__.cpython-36.pyc b/q03_better_event/__pycache__/__init__.cpython-36.pyc index a1d4f17..fe44118 100644 Binary files a/q03_better_event/__pycache__/__init__.cpython-36.pyc and b/q03_better_event/__pycache__/__init__.cpython-36.pyc differ diff --git a/q03_better_event/__pycache__/build.cpython-36.pyc b/q03_better_event/__pycache__/build.cpython-36.pyc index 98a743b..1a4a0a9 100644 Binary files a/q03_better_event/__pycache__/build.cpython-36.pyc and b/q03_better_event/__pycache__/build.cpython-36.pyc differ diff --git a/q03_better_event/build.py b/q03_better_event/build.py index 4756f94..904ea07 100644 --- a/q03_better_event/build.py +++ b/q03_better_event/build.py @@ -1,13 +1,25 @@ +# %load q03_better_event/build.py #default imports from greyatomlib.olympics_project_new.q02_country_operations.build import q02_country_operations, q01_rename_columns import numpy as np +import pandas as pd #Previous function -path = "./data/olympics.csv" +path = './data/olympics.csv' OlympicsDF=q01_rename_columns(path) OlympicsDF=q02_country_operations(OlympicsDF) +def q03_better_event(OlympicsDF=OlympicsDF): + BetterEvent_col = [] + for i, j in zip(OlympicsDF['Total_Summer'], OlympicsDF['Total_Winter']): + if i > j: + BetterEvent_col.append('Summer') + elif i < j: + BetterEvent_col.append('Winter') + else: + BetterEvent_col.append('Both') - + OlympicsDF['BetterEvent'] = BetterEvent_col + return OlympicsDF diff --git a/q03_better_event/tests/__pycache__/__init__.cpython-36.pyc b/q03_better_event/tests/__pycache__/__init__.cpython-36.pyc index 3988395..760aaed 100644 Binary files a/q03_better_event/tests/__pycache__/__init__.cpython-36.pyc and b/q03_better_event/tests/__pycache__/__init__.cpython-36.pyc differ diff --git a/q03_better_event/tests/__pycache__/test.cpython-36.pyc b/q03_better_event/tests/__pycache__/test.cpython-36.pyc index 2b9c3a2..481dcce 100644 Binary files a/q03_better_event/tests/__pycache__/test.cpython-36.pyc and b/q03_better_event/tests/__pycache__/test.cpython-36.pyc differ diff --git a/q04_find_top_10/__pycache__/__init__.cpython-36.pyc b/q04_find_top_10/__pycache__/__init__.cpython-36.pyc index d8fba08..9aac29b 100644 Binary files a/q04_find_top_10/__pycache__/__init__.cpython-36.pyc and b/q04_find_top_10/__pycache__/__init__.cpython-36.pyc differ diff --git a/q04_find_top_10/__pycache__/build.cpython-36.pyc b/q04_find_top_10/__pycache__/build.cpython-36.pyc index 0068560..1303aae 100644 Binary files a/q04_find_top_10/__pycache__/build.cpython-36.pyc and b/q04_find_top_10/__pycache__/build.cpython-36.pyc differ diff --git a/q04_find_top_10/build.py b/q04_find_top_10/build.py index 9f283b7..068e340 100644 --- a/q04_find_top_10/build.py +++ b/q04_find_top_10/build.py @@ -1,8 +1,35 @@ +# %load q04_find_top_10/build.py # default imports from greyatomlib.olympics_project_new.q03_better_event.build import q03_better_event,q02_country_operations, q01_rename_columns -path = "./data/olympics.csv" +path = './data/olympics.csv' + OlympicsDF=q01_rename_columns(path) OlympicsDF=q02_country_operations(OlympicsDF) OlympicsDF=q03_better_event(OlympicsDF) +Total_Summer_col = 'Total_Summer' +Total_Winter_col = 'Total_Winter' +Total_col = 'Total' + + +def q04_find_top_10(OlympicsDF=OlympicsDF, Total_Summer_col = Total_Summer_col, Total_Winter_col = Total_Winter_col, Total_col = Total_col): + ascending_country_names = OlympicsDF.sort_values(by=['Country_Name'], ascending=True) + + descending_total_summer = ascending_country_names.sort_values(by=['Total_Summer'], ascending=False) + descending_total_winter = ascending_country_names.sort_values(by=['Total_Winter'], ascending=False) + descending_total = ascending_country_names.sort_values(by=['Total'], ascending=False) + + top_10_summer = [] + top_10_winter = [] + top_10_total = [] + count = 1 + while (count<=10): + top_10_summer.append(OlympicsDF.iloc[descending_total_summer.index[count],16]) + top_10_winter.append(OlympicsDF.iloc[descending_total_winter.index[count],16]) + top_10_total.append(OlympicsDF.iloc[descending_total.index[count],16]) + count = count + 1 + common_countries = list(set(top_10_summer).intersection(set(top_10_winter).intersection(top_10_total))) + return top_10_summer, top_10_winter, top_10_total, common_countries + + diff --git a/q04_find_top_10/tests/__pycache__/__init__.cpython-36.pyc b/q04_find_top_10/tests/__pycache__/__init__.cpython-36.pyc index b6dea62..ba5e8b9 100644 Binary files a/q04_find_top_10/tests/__pycache__/__init__.cpython-36.pyc and b/q04_find_top_10/tests/__pycache__/__init__.cpython-36.pyc differ diff --git a/q04_find_top_10/tests/__pycache__/test.cpython-36.pyc b/q04_find_top_10/tests/__pycache__/test.cpython-36.pyc index f2adc9c..3798f5d 100644 Binary files a/q04_find_top_10/tests/__pycache__/test.cpython-36.pyc and b/q04_find_top_10/tests/__pycache__/test.cpython-36.pyc differ