diff --git a/__pycache__/__init__.cpython-36.pyc b/__pycache__/__init__.cpython-36.pyc new file mode 100644 index 0000000..b88f761 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..720ef67 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..04661f8 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..d6bb6ad 100644 --- a/q01_rename_columns/build.py +++ b/q01_rename_columns/build.py @@ -1,5 +1,30 @@ +# %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=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 + +q01_rename_columns(path).shape + + + + diff --git a/q01_rename_columns/tests/__pycache__/__init__.cpython-36.pyc b/q01_rename_columns/tests/__pycache__/__init__.cpython-36.pyc index ee14684..e218db4 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..74c52e2 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..d87ed0a 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..28faa6c 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..995703e 100644 --- a/q02_country_operations/build.py +++ b/q02_country_operations/build.py @@ -1,11 +1,34 @@ +# %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 remove_text_inside_brackets(text, brackets='()[]'): + count = [0] * (len(brackets) // 2) # count open/close brackets + saved_chars = [] + for character in text: + for i, b in enumerate(brackets): + if character == b: # found bracket + kind, is_close = divmod(i, 2) + count[kind] += (-1)**is_close # : open, : close + if count[kind] < 0: # unbalanced bracket + count[kind] = 0 # keep it + else: # found bracket to remove + break + else: # character is not a [balanced] bracket + if not any(count): # outside brackets + saved_chars.append(character) + return ''.join(saved_chars).replace('\xa0','') +def q02_country_operations(OlympicsDF): + OlympicsDF['Country_Name']=OlympicsDF['Country'] + OlympicsDF['Country_Name']= OlympicsDF['Country_Name'].apply(remove_text_inside_brackets) + + return OlympicsDF +df=q02_country_operations(OlympicsDF) +df.iloc[100,16] diff --git a/q02_country_operations/tests/__pycache__/__init__.cpython-36.pyc b/q02_country_operations/tests/__pycache__/__init__.cpython-36.pyc index 3d1192a..f06d1b7 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..bb1ae29 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..011046a 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..80e6edf 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..1d8c8de 100644 --- a/q03_better_event/build.py +++ b/q03_better_event/build.py @@ -1,11 +1,29 @@ +# %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 better_perf(x): + if x[0] > x[1]: + return 'Summer' + elif x[0]< x[1] : + return 'Winter' + else: + return 'Both' + +def q03_better_event(OlympicsDF): + OlympicsDF['BetterEvent'] =OlympicsDF[['Total_Summer','Total_Winter']].apply(better_perf, axis=1) + + 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..89a60f5 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..0754073 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..aa1ab2b 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..116086a 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..9f6c49c 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' OlympicsDF=q01_rename_columns(path) OlympicsDF=q02_country_operations(OlympicsDF) OlympicsDF=q03_better_event(OlympicsDF) +def q04_find_top_10(OlympicsDF,variable2,variable3,variable4): + + TSummer=OlympicsDF[:-1].sort_values(by=variable2, ascending=False).head(10)[['Country_Name']].index + TWinter=OlympicsDF[:-1].sort_values(by=variable3, ascending=False).head(10)[['Country_Name']].index + T10= OlympicsDF[:-1].sort_values(by=variable4, ascending=False).head(10)[['Country_Name']].index + + Top10Summer = list(OlympicsDF.iloc[TSummer]['Country_Name']) + Top10Winter = list(OlympicsDF.iloc[TWinter]['Country_Name']) + Top10 = list(OlympicsDF.iloc[T10]['Country_Name']) + + Common= [x for x in Top10Summer if x in Top10Winter and x in Top10] + return Top10Summer,Top10Winter, Top10, Common + +q04_find_top_10(OlympicsDF,'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..678e160 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..9eafb01 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..bc9f458 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..0e29ad2 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..6feb52d 100644 --- a/q05_top_10_plotting/build.py +++ b/q05_top_10_plotting/build.py @@ -1,14 +1,36 @@ +# %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): + dftopsummer =OlympicsDF[OlympicsDF['Country_Name'].isin(Top10Summer)] + dfTop10Winter =OlympicsDF[OlympicsDF['Country_Name'].isin(Top10Winter)] + dfCommon =OlympicsDF[OlympicsDF['Country_Name'].isin(Top10)] + plt.bar(dftopsummer['Country_Name'], dftopsummer['Total'],align='center', alpha=0.5) + plt.ylabel('Total Medal') + plt.xlabel('Country Name') + plt.title('Top 10 Summer') + plt.show() + + plt.bar(dfTop10Winter['Country_Name'], dfTop10Winter['Total'],align='center', alpha=0.5) + plt.ylabel('Total Medal') + plt.xlabel('Country Name') + plt.title('Top 10 Winter') + plt.show() + + plt.bar(dfCommon['Country_Name'], dfCommon['Total'],align='center', alpha=0.5) + plt.ylabel('Total Medal') + plt.xlabel('Country Name') + plt.title('Top 10 ') + 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..c3f19ef 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..f71f4b7 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..c4c1892 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..0e43f36 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..3a19bc0 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): + df_summer = OlympicsDF[OlympicsDF['Country_Name'].isin (Top10Summer)] + df_summer['Gold_Ratio'] = df_summer['Gold_Summer']/df_summer['Total_Summer'] + variable1= str(list(df_summer.loc[df_summer['Gold_Ratio'] == df_summer['Gold_Ratio'].max()]['Country_Name'])[0]) + + df_winter = OlympicsDF[OlympicsDF['Country_Name'].isin (Top10Winter)] + df_winter['Gold_Ratio'] = df_winter['Gold_Winter']/df_winter['Total_Winter'] + variable2= str(list(df_winter.loc[df_winter['Gold_Ratio'] == df_winter['Gold_Ratio'].max()]['Country_Name'])[0]) + + df_common = OlympicsDF[OlympicsDF['Country_Name'].isin (Top10)] + df_common['Gold_Ratio'] = df_common['Gold_Total']/df_common['Total'] + variable3= str(list(df_common.loc[df_common['Gold_Ratio'] == df_common['Gold_Ratio'].max()]['Country_Name'])[0]) + + return variable1,variable2,variable3 + diff --git a/q06_golden_winner/tests/__pycache__/__init__.cpython-36.pyc b/q06_golden_winner/tests/__pycache__/__init__.cpython-36.pyc index 78c9f23..fb76efc 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..b95fe05 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..44fb401 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..f20213f 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..739e798 100644 --- a/q07_unusual_performances/build.py +++ b/q07_unusual_performances/build.py @@ -1,5 +1,21 @@ +# %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): + + + df =OlympicsDF[:-1] + #quant_df = df['Total'].quantile([low, high]) + df_low= df[low >= df['Total']]['Country_Name'] + df_high=df[high <= df['Total']]['Country_Name'] + return df_low,df_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..b1e0589 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..1c0b10c 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