diff --git a/__pycache__/__init__.cpython-36.pyc b/__pycache__/__init__.cpython-36.pyc new file mode 100644 index 0000000..6100ce7 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..e42d635 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..aeda565 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..0249f8f 100644 --- a/q01_rename_columns/build.py +++ b/q01_rename_columns/build.py @@ -1,5 +1,27 @@ +# %load q01_rename_columns/build.py # default imports import pandas as pd +def q01_rename_columns(path): + df = pd.read_csv(path,skiprows=1) + df.rename(columns={'Unnamed: 0':'Country', + '01 !':'Gold_Summer', + '02 !':'Silver_Summer', + '03 !':'Bronze_Summer', + 'Total':'Total_Summer', + '01 !.1':'Gold_Winter', + '02 !.1':'Silver_Winter', + '03 !.1': 'Bronze_Winter', + 'Total.1':'Total_Winter', + '01 !.2':'Gold_Total', + '02 !.2':'Silver_Total', + '03 !.2':'Bronze_Total', + '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..93b6ad9 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..476b450 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..50d63d7 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..602c3a5 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..6cff658 100644 --- a/q02_country_operations/build.py +++ b/q02_country_operations/build.py @@ -1,11 +1,15 @@ +# %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" +path = './data/olympics.csv' OlympicsDF=q01_rename_columns(path) +def q02_country_operations(df): + df['Country_Name'] = (df['Country'].str.split('(',1).str)[0].str.strip() + return df +#print(q02_country_operations(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..12287d8 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..3b118e4 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..fd64e3f 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..f5f9118 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..69d7d43 100644 --- a/q03_better_event/build.py +++ b/q03_better_event/build.py @@ -1,11 +1,24 @@ +# %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 #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): + for i in range(len(OlympicsDF)): + if OlympicsDF.loc[i,'Gold_Winter'] + OlympicsDF.loc[i,'Silver_Winter'] + OlympicsDF.loc[i,'Bronze_Winter'] > OlympicsDF.loc[i,'Gold_Summer'] + OlympicsDF.loc[i,'Silver_Summer'] + OlympicsDF.loc[i,'Bronze_Summer']: + OlympicsDF.loc[i,'BetterEvent'] = 'Winter' + elif OlympicsDF.loc[i,'Gold_Winter'] + OlympicsDF.loc[i,'Silver_Winter'] + OlympicsDF.loc[i,'Bronze_Winter'] == OlympicsDF.loc[i,'Gold_Summer'] + OlympicsDF.loc[i,'Silver_Summer'] + OlympicsDF.loc[i,'Bronze_Summer']: + OlympicsDF.loc[i,'BetterEvent'] = 'Both' + else: + OlympicsDF.loc[i,'BetterEvent'] = 'Summer' + 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..40ec4ac 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..4c601c4 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..76b45a8 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..289a30f 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..a11cb48 100644 --- a/q04_find_top_10/build.py +++ b/q04_find_top_10/build.py @@ -1,8 +1,28 @@ +# %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) +def q04_find_top_10(OlympicsDF,col1,col2,col3): + sorted_summer = OlympicsDF[['Country_Name',col1]].sort_values(col1,ascending=False) + top_10_summer = (sorted_summer[1:].head(10))['Country_Name'] + + sorted_winter = OlympicsDF[['Country_Name',col2]].sort_values(col2,ascending=False) + top_10_winter = (sorted_winter[1:].head(10))['Country_Name'] + + sorted_total = OlympicsDF[['Country_Name',col3]].sort_values(col3,ascending=False) + top_10_total = (sorted_total[1:].head(10))['Country_Name'] + + common = list(set(top_10_summer) & set(top_10_winter) & set(top_10_total)) + + return list(top_10_summer),list(top_10_winter),list(top_10_total),common + + + + + + 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..4c8172e 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..12cfc19 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..039a921 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..d356c0e 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..6d37876 100644 --- a/q05_top_10_plotting/build.py +++ b/q05_top_10_plotting/build.py @@ -1,13 +1,33 @@ +# %load q05_top_10_plotting/build.py # 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') +Top10Summer,Top10Winter, Top10, Common = q04_find_top_10(OlympicsDF,'Total_Summer', 'Total_Winter','Total') +def q05_top_10_plotting(OlympicsDF,Top10Summer,Top10Winter,Top10): + + #For Summer + top_10_summer = OlympicsDF[OlympicsDF['Country_Name'].isin(Top10Summer)][['Country_Name','Total_Summer']] + plt.bar(top_10_summer.Country_Name,top_10_summer.Total_Summer) + plt.xticks(rotation=45) + plt.show() + + #For Winter: + top_10_winter = OlympicsDF[OlympicsDF['Country_Name'].isin(Top10Winter)][['Country_Name','Total_Winter']] + plt.bar(top_10_winter.Country_Name,top_10_winter.Total_Winter) + plt.xticks(rotation=45) + plt.show() + + top_10 = OlympicsDF[OlympicsDF['Country_Name'].isin(Top10)][['Country_Name','Total']] + plt.bar(top_10.Country_Name,top_10.Total) + plt.xticks(rotation=45) + 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..d1f8780 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..59234c4 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..b8a9349 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..88e7e43 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..a167ace 100644 --- a/q06_golden_winner/build.py +++ b/q06_golden_winner/build.py @@ -1,10 +1,32 @@ +# %load q06_golden_winner/build.py # default imports 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): + OlympicsDF['GoldRatioSummer'] = OlympicsDF.loc[:,'Gold_Summer']/ OlympicsDF.loc[:,'Total_Summer'] + OlympicsDF['GoldRatioWinter'] = OlympicsDF.loc[:,'Gold_Winter']/ OlympicsDF.loc[:,'Total_Winter'] + OlympicsDF['GoldRatioTotal'] = OlympicsDF.loc[:,'Gold_Total']/ OlympicsDF.loc[:,'Total'] + + top_10_summer_df = OlympicsDF[OlympicsDF['Country_Name'].isin(Top10Summer)] + top_10_winter_df = OlympicsDF[OlympicsDF['Country_Name'].isin(Top10Winter)] + top_10 = OlympicsDF[OlympicsDF['Country_Name'].isin(Top10)] + + + top_gold_summer = top_10_summer_df.sort_values('GoldRatioSummer',ascending=False).iloc[0,16] + top_gold_winter = top_10_winter_df.sort_values('GoldRatioWinter',ascending=False).iloc[0,16] + top_total = top_10.sort_values('GoldRatioTotal',ascending=False).iloc[0,16] + + return top_gold_summer,top_gold_winter,top_total + + + + + + diff --git a/q06_golden_winner/tests/__pycache__/__init__.cpython-36.pyc b/q06_golden_winner/tests/__pycache__/__init__.cpython-36.pyc index 78c9f23..7305ea2 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..0899baf 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 diff --git a/q07_unusual_performances/__pycache__/__init__.cpython-36.pyc b/q07_unusual_performances/__pycache__/__init__.cpython-36.pyc index 288c374..ec6469a 100644 Binary files a/q07_unusual_performances/__pycache__/__init__.cpython-36.pyc and b/q07_unusual_performances/__pycache__/__init__.cpython-36.pyc differ diff --git a/q07_unusual_performances/__pycache__/build.cpython-36.pyc b/q07_unusual_performances/__pycache__/build.cpython-36.pyc index b5f4425..6cc57d2 100644 Binary files a/q07_unusual_performances/__pycache__/build.cpython-36.pyc and b/q07_unusual_performances/__pycache__/build.cpython-36.pyc differ diff --git a/q07_unusual_performances/build.py b/q07_unusual_performances/build.py index a264d21..3c47bd0 100644 --- a/q07_unusual_performances/build.py +++ b/q07_unusual_performances/build.py @@ -1,5 +1,22 @@ +# %load q07_unusual_performances/build.py # default imports from greyatomlib.olympics_project_new.q02_country_operations.build import q02_country_operations, q01_rename_columns -path = "./data/olympics.csv" +path = './data/olympics.csv' OlympicsDF=q01_rename_columns(path) OlympicsDF=q02_country_operations(OlympicsDF) + +def q07_unusual_performances(OlympicsDF,lq,uq): + + #Quant = OlympicsDF.Total.quantile([lq,up]) + #low_quant = Quant.iloc[0] + #upper_quant = Quant.iloc[1] + worse_countries = OlympicsDF[OlympicsDF['Total']<=lq].Country_Name + better_countries = OlympicsDF[OlympicsDF['Total'] > uq].Country_Name + return worse_countries,better_countries.iloc[:-1] + +#q07_unusual_performances(OlympicsDF, quant_df.loc[low], quant_df.loc[high]) + + + + + diff --git a/q07_unusual_performances/tests/__pycache__/__init__.cpython-36.pyc b/q07_unusual_performances/tests/__pycache__/__init__.cpython-36.pyc index eea34b6..d86ed8a 100644 Binary files a/q07_unusual_performances/tests/__pycache__/__init__.cpython-36.pyc and b/q07_unusual_performances/tests/__pycache__/__init__.cpython-36.pyc differ diff --git a/q07_unusual_performances/tests/__pycache__/test.cpython-36.pyc b/q07_unusual_performances/tests/__pycache__/test.cpython-36.pyc index 44dbdd5..13d004c 100644 Binary files a/q07_unusual_performances/tests/__pycache__/test.cpython-36.pyc and b/q07_unusual_performances/tests/__pycache__/test.cpython-36.pyc differ