diff --git a/__pycache__/__init__.cpython-36.pyc b/__pycache__/__init__.cpython-36.pyc new file mode 100644 index 0000000..fca7fab 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..3b2b473 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..c9ec969 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..f3b7b7b 100644 --- a/q01_rename_columns/build.py +++ b/q01_rename_columns/build.py @@ -1,5 +1,19 @@ +# %load q01_rename_columns/build.py # default imports import pandas as pd +path='./data/olympics.csv' + +def q01_rename_columns(path): + + df=pd.read_csv(path,skiprows=[0]) + df.rename(columns={'Combined total':'Total','Total.1':'Total_Winter','Total':'Total_Summer'},inplace=True) + df.columns.values[0] = 'Country' + df.columns = df.columns.str.replace('01 !', 'Gold_Summer') + df.columns = df.columns.str.replace('02 !', 'Silver_Summer') + df.columns = df.columns.str.replace('03 !', 'Bronze_Summer') + df.columns = df.columns.str.replace('Summer.1', 'Winter') + df.columns = df.columns.str.replace('Summer.2', 'Total') + 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..23bc705 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..8eeeb09 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..105008a 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..a3243a3 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..146e1f6 100644 --- a/q02_country_operations/build.py +++ b/q02_country_operations/build.py @@ -1,8 +1,17 @@ +# %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) +import pandas as pd + +def q02_country_operations(OlympicsDF): + + + OlympicsDF['Country_Name']=OlympicsDF['Country'].str.replace(' ', '') + OlympicsDF.iloc[100,16]=OlympicsDF.iloc[100,16].replace('\xa0(POR)','') + 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..26b84d1 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..5383b54 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..b30eddb 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..9f7e2bc 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..75b09a0 100644 --- a/q03_better_event/build.py +++ b/q03_better_event/build.py @@ -1,11 +1,20 @@ +# %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): + + + OlympicsDF['BetterEvent']=np.select([OlympicsDF['Total_Summer']>OlympicsDF['Total_Winter'],OlympicsDF['Total_Winter']>OlympicsDF['Total_Summer'],OlympicsDF['Total_Summer']==OlympicsDF['Total_Winter']],['Summer','Winter','Both']) + + 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..f1b3a3e 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..b181e11 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..87bb52e 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..1814aec 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..9be50d0 100644 --- a/q04_find_top_10/build.py +++ b/q04_find_top_10/build.py @@ -1,8 +1,17 @@ +# %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,Total_Summer,Total_Winter,Total): + OlympicsDF.drop(OlympicsDF.tail(1).index,inplace=True) + list1=list(OlympicsDF.nlargest(10,'Total_Summer')['Country_Name'].values) + list2=list(OlympicsDF.nlargest(10,'Total_Winter')['Country_Name'].values) + list3=list(OlympicsDF.nlargest(10,'Total')['Country_Name'].values) + list4=list(set(list1).intersection(list2).intersection(list3)) + return list1,list2,list3,list4 +OlympicsDF 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..cddbac2 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..0d1a4c7 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..da0541a 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..ac00797 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..f0efb5f 100644 --- a/q05_top_10_plotting/build.py +++ b/q05_top_10_plotting/build.py @@ -1,15 +1,34 @@ +# %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') +def q05_top_10_plotting(OlympicsDF,Top10Summer,Top10Winter,Top10): + + + + plt.bar(Top10Summer,list(OlympicsDF.nlargest(10,'Total_Summer')['Total_Summer'].values)) + plt.xlabel('Country Name') + plt.ylabel('Total Medals') + plt.title('Top 10 Summer') + plt.bar(Top10Winter,list(OlympicsDF.nlargest(10,'Total_Winter')['Total_Winter'].values)) + plt.xlabel('Country Name') + plt.ylabel('Total Medals') + plt.title('Top 10 Winter') + plt.bar(Top10,list(OlympicsDF.nlargest(10,'Total')['Total'].values)) + plt.xlabel('Country Name') + plt.ylabel('Total Medals') + plt.title('Top 10') + plt.show() - +Top10Summer +list(OlympicsDF.nlargest(10,'Total_Summer')['Total_Summer'].values) 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..f1de668 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..4200144 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..d5d0b86 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..4e9fac1 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..ed41baa 100644 --- a/q06_golden_winner/build.py +++ b/q06_golden_winner/build.py @@ -1,10 +1,26 @@ +# %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.drop(OlympicsDF.tail(1).index,inplace=True) + df1 = OlympicsDF.sort_values('Total_Summer',ascending = False).groupby('Country').head(2).iloc[1:11,:] + df1['ratio']=df1['Gold_Summer']/df1['Total_Summer'] + str1=df1.nlargest(1,'ratio')['Country_Name'].values.tolist()[0] + + df2 = OlympicsDF.sort_values('Total_Winter',ascending = False).groupby('Country').head(2).iloc[1:11,:] + df2['ratio']=df2['Gold_Winter']/df2['Total_Winter'] + str2=df2.nlargest(1,'ratio')['Country_Name'].values.tolist()[0] + + df3 = OlympicsDF.sort_values('Total',ascending = False).groupby('Country').head(2).iloc[1:11,:] + df3['ratio']=df3['Gold_Total']/df3['Total'] + str3=df3.nlargest(1,'ratio')['Country_Name'].values.tolist()[0] + + return str1,str2,str3 + diff --git a/q06_golden_winner/tests/__pycache__/__init__.cpython-36.pyc b/q06_golden_winner/tests/__pycache__/__init__.cpython-36.pyc index 78c9f23..45eb5e4 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..4c335b7 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..6901637 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..e1484db 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..0d9561d 100644 --- a/q07_unusual_performances/build.py +++ b/q07_unusual_performances/build.py @@ -1,5 +1,28 @@ +# %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,low,high): + + OlympicsDF.drop(OlympicsDF.tail(1).index,inplace=True) + + quant1=OlympicsDF['Total'].quantile(0.05) + quant2=OlympicsDF['Total'].quantile(0.95) + better=OlympicsDF[OlympicsDF['Total']>quant2]['Country_Name'] + better=better.drop(labels=23) + worse=OlympicsDF[OlympicsDF['Total']<=quant1]['Country_Name'] + + return worse,better + +quant1=OlympicsDF['Total'].quantile(0.05) +quant2=OlympicsDF['Total'].quantile(0.95) +better=OlympicsDF[OlympicsDF['Total']>quant2]['Country_Name'] +worse=OlympicsDF[OlympicsDF['Total']<=quant1]['Country_Name'] + +OlympicsDF.drop(OlympicsDF.tail(1).index,inplace=True) +better + + diff --git a/q07_unusual_performances/tests/__pycache__/__init__.cpython-36.pyc b/q07_unusual_performances/tests/__pycache__/__init__.cpython-36.pyc index eea34b6..184d211 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..c98675c 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