diff --git a/__pycache__/__init__.cpython-36.pyc b/__pycache__/__init__.cpython-36.pyc new file mode 100644 index 0000000..0722213 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..a024a16 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..17850db 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..bb765ad 100644 --- a/q01_rename_columns/build.py +++ b/q01_rename_columns/build.py @@ -1,5 +1,26 @@ -# default imports import pandas as pd +path = './data/olympics.csv' + +def q01_rename_columns(path): + path = './data/olympics.csv' + df = pd.read_csv(path, skiprows=[0]) + df.rename(columns= {'Unnamed: 0':'Country','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', + 'Total':'Total_Summer', + 'Total.1':'Total_Winter', + 'Combined total':'Total'},inplace= True) + return df + + + + diff --git a/q01_rename_columns/tests/__pycache__/__init__.cpython-36.pyc b/q01_rename_columns/tests/__pycache__/__init__.cpython-36.pyc index ee14684..486c167 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..d26a5d0 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..f4a250a 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..57c7216 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..14808f7 100644 --- a/q02_country_operations/build.py +++ b/q02_country_operations/build.py @@ -1,8 +1,20 @@ -# 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) +import pandas as pd +path = './data/olympics.csv' +df = pd.read_csv(path, skiprows=[0]) +OlympicsDF=q01_rename_columns(path) + + +def q02_country_operations(OlympicsDF): + OlympicsDF['Country_Name']=(OlympicsDF['Country'].str.split('(').str)[0].str.strip() + return(OlympicsDF) + +q02_country_operations(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..9757595 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..3da8fd8 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..f2891cb 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..5ff8e60 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..fdfcb09 100644 --- a/q03_better_event/build.py +++ b/q03_better_event/build.py @@ -1,11 +1,17 @@ -#default imports + from greyatomlib.olympics_project_new.q02_country_operations.build import q02_country_operations, q01_rename_columns import numpy as np -#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'] = np.where(OlympicsDF['Total_Summer'] > OlympicsDF['Total_Winter'], 'Summer', np.where(OlympicsDF['Total_Summer'] == OlympicsDF['Total_Winter'], 'Both', 'Winter')) + return OlympicsDF + +q03_better_event(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..e6a88ff 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..39b2bb9 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..fb23e7a 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..6e2fb9c 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..43d7f0d 100644 --- a/q04_find_top_10/build.py +++ b/q04_find_top_10/build.py @@ -1,8 +1,27 @@ +# %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' +import pandas as pd OlympicsDF=q01_rename_columns(path) OlympicsDF=q02_country_operations(OlympicsDF) -OlympicsDF=q03_better_event(OlympicsDF) +OlympicsDF=q03_better_event(OlympicsDF) +OlympicsDF=OlympicsDF.drop([146]) + +def q04_find_top_10(df=OlympicsDF, str1 = 'Total_Summer', str2 = 'Total_Winter', str3 = 'Total'): + top10_summer = list(OlympicsDF.nlargest(10, 'Total_Summer')['Country_Name']) + top10_winter = list(OlympicsDF.nlargest(10, 'Total_Winter')['Country_Name']) + top10_total = list(OlympicsDF.nlargest(10, 'Total')['Country_Name']) + overall = list(set(top10_summer).intersection(set(top10_winter), set(top10_total))) + + return top10_summer, top10_winter, top10_total, overall + +q04_find_top_10('Total_Summer', 'Total_Winter', 'Total') + + + + + + 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..dd0844c 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..f508862 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 diff --git a/q05_top_10_plotting/__pycache__/__init__.cpython-36.pyc b/q05_top_10_plotting/__pycache__/__init__.cpython-36.pyc index 36afe44..bf62469 100644 Binary files a/q05_top_10_plotting/__pycache__/__init__.cpython-36.pyc and b/q05_top_10_plotting/__pycache__/__init__.cpython-36.pyc differ diff --git a/q05_top_10_plotting/__pycache__/build.cpython-36.pyc b/q05_top_10_plotting/__pycache__/build.cpython-36.pyc index f75beb5..063cfe9 100644 Binary files a/q05_top_10_plotting/__pycache__/build.cpython-36.pyc and b/q05_top_10_plotting/__pycache__/build.cpython-36.pyc differ diff --git a/q05_top_10_plotting/build.py b/q05_top_10_plotting/build.py index 78064cc..56a2622 100644 --- a/q05_top_10_plotting/build.py +++ b/q05_top_10_plotting/build.py @@ -1,13 +1,37 @@ -# default imports import matplotlib.pyplot as plt from greyatomlib.olympics_project_new.q04_find_top_10.build import q04_find_top_10, q03_better_event, q02_country_operations, q01_rename_columns plt.switch_backend('agg') -path = "./data/olympics.csv" +path = './data/olympics.csv' OlympicsDF=q01_rename_columns(path) OlympicsDF=q02_country_operations(OlympicsDF) OlympicsDF=q03_better_event(OlympicsDF) Top10Summer,Top10Winter, Top10, Common =q04_find_top_10(OlympicsDF,'Total_Summer', 'Total_Winter','Total') +def q05_top_10_plotting(OlympicsDF,Top10Summer,Top10Winter,Top10): + + SummerOlympics = OlympicsDF[OlympicsDF['Country_Name'].isin(Top10Summer)] + WinterOlympics = OlympicsDF[OlympicsDF['Country_Name'].isin(Top10Winter)] + FinalsOlympics = OlympicsDF[OlympicsDF['Country_Name'].isin(Top10)] + + plt.subplot(2,2,1) + plt.bar(SummerOlympics['Country_Name'], SummerOlympics['Total_Summer'], color= 'red', label= 'Top 10 Summer') + plt.xlabel('Country') + plt.ylabel('Total Medals') + + plt.subplot(2,2,2) + plt.bar(WinterOlympics['Country_Name'], WinterOlympics['Total_Summer'], color= 'blue', label= 'Top 10 Winter') + plt.xlabel('Country') + plt.ylabel('Total Medals') + + plt.subplot(2,2,3) + plt.bar(FinalsOlympics['Country_Name'], FinalsOlympics['Total_Summer'], color= 'green', label= 'Top 10') + plt.xlabel('Country') + plt.ylabel('Total Medals') + + plt.tight_layout() + plt.show(); + + diff --git a/q05_top_10_plotting/tests/__pycache__/__init__.cpython-36.pyc b/q05_top_10_plotting/tests/__pycache__/__init__.cpython-36.pyc index 3fdeb4e..3072d16 100644 Binary files a/q05_top_10_plotting/tests/__pycache__/__init__.cpython-36.pyc and b/q05_top_10_plotting/tests/__pycache__/__init__.cpython-36.pyc differ diff --git a/q05_top_10_plotting/tests/__pycache__/test.cpython-36.pyc b/q05_top_10_plotting/tests/__pycache__/test.cpython-36.pyc index ddca5ec..de6e668 100644 Binary files a/q05_top_10_plotting/tests/__pycache__/test.cpython-36.pyc and b/q05_top_10_plotting/tests/__pycache__/test.cpython-36.pyc differ diff --git a/q06_golden_winner/__pycache__/__init__.cpython-36.pyc b/q06_golden_winner/__pycache__/__init__.cpython-36.pyc index 52aa4b0..4f01c05 100644 Binary files a/q06_golden_winner/__pycache__/__init__.cpython-36.pyc and b/q06_golden_winner/__pycache__/__init__.cpython-36.pyc differ diff --git a/q06_golden_winner/__pycache__/build.cpython-36.pyc b/q06_golden_winner/__pycache__/build.cpython-36.pyc index 03a0fd0..aa77d2f 100644 Binary files a/q06_golden_winner/__pycache__/build.cpython-36.pyc and b/q06_golden_winner/__pycache__/build.cpython-36.pyc differ diff --git a/q06_golden_winner/build.py b/q06_golden_winner/build.py index 4789e29..331e8da 100644 --- a/q06_golden_winner/build.py +++ b/q06_golden_winner/build.py @@ -1,10 +1,31 @@ -# default imports +import pandas as pd +import numpy as np from greyatomlib.olympics_project_new.q04_find_top_10.build import q04_find_top_10, 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) Top10Summer,Top10Winter, Top10, Common =q04_find_top_10(OlympicsDF,'Total_Summer', 'Total_Winter','Total') +def q06_golden_winner(OlympicsDF, Top10Summer, Top10Winter, Top10): + + SummerOly = OlympicsDF[OlympicsDF['Country_Name'].isin(Top10Summer)] + S_Ratio= list(SummerOly['Gold_Summer']/SummerOly['Total_Summer']) + Summer_Country = SummerOly.iloc[np.argmax(S_Ratio), 16] + + WinterOly = OlympicsDF[OlympicsDF['Country_Name'].isin(Top10Winter)] + W_Ratio= list(WinterOly['Gold_Winter']/WinterOly['Total_Winter']) + Winter_Country = WinterOly.iloc[np.argmax(W_Ratio), 16] + + TotalOly = OlympicsDF[OlympicsDF['Country_Name'].isin(Top10)] + T_Ratio= list(TotalOly['Gold_Total']/TotalOly['Total']) + Total_Country = TotalOly.iloc[np.argmax(T_Ratio), 16] + + + + return Summer_Country, Winter_Country, Total_Country + +q06_golden_winner(OlympicsDF, Top10Summer, Top10Winter, Top10) + diff --git a/q06_golden_winner/tests/__pycache__/__init__.cpython-36.pyc b/q06_golden_winner/tests/__pycache__/__init__.cpython-36.pyc index 78c9f23..b3333f2 100644 Binary files a/q06_golden_winner/tests/__pycache__/__init__.cpython-36.pyc and b/q06_golden_winner/tests/__pycache__/__init__.cpython-36.pyc differ diff --git a/q06_golden_winner/tests/__pycache__/test.cpython-36.pyc b/q06_golden_winner/tests/__pycache__/test.cpython-36.pyc index 8c58d9e..97e6eee 100644 Binary files a/q06_golden_winner/tests/__pycache__/test.cpython-36.pyc and b/q06_golden_winner/tests/__pycache__/test.cpython-36.pyc differ