diff --git a/__pycache__/__init__.cpython-36.pyc b/__pycache__/__init__.cpython-36.pyc new file mode 100644 index 0000000..f878f31 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..761214e 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..655eb9d 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..e521c29 100644 --- a/q01_rename_columns/build.py +++ b/q01_rename_columns/build.py @@ -1,5 +1,37 @@ +# %load q01_rename_columns/build.py # default imports import pandas as pd +def q01_rename_columns(path): + df = pd.read_csv(path, skiprows=[0]) + + for index, value in enumerate(df.columns): + if '01' in value: + if not 'Games' in df.columns[index-1][1:]: + df.rename(columns = {value: 'Gold_' + df.columns[index-1][2:]}, inplace = True) + if '02' in value: + if not 'Games' in df.columns[index-2][1:]: + df.rename(columns = {value: 'Silver_' + df.columns[index-2][2:]}, inplace = True) + if '03' in value: + if not 'Games' in df.columns[index-3][1:]: + df.rename(columns = {value: 'Bronze_' + df.columns[index-3][2:]}, inplace = True) + if 'Total' in value: + df.rename(columns = {value: 'Total_' + df.columns[index-4][2:]}, inplace = True) + + df.rename(columns={ df.columns[0]: 'Country' }, inplace = True) + df.rename(columns={ df.columns[12]: 'Gold_Total' }, inplace = True) + df.rename(columns={ df.columns[13]: 'Silver_Total' }, inplace = True) + df.rename(columns={ df.columns[14]: 'Bronze_Total' }, inplace = True) + df.rename(columns={ 'Combined total': 'Total' }, inplace = True) + + return df +q01_rename_columns('./data/olympics.csv') +#df = pd.read_csv('./data/olympics.csv', skiprows=[0]) + +# df = pd.read_csv('./data/olympics.csv', skiprows=[0]) +# df.columns[14] +# a['Gold_ Summer'] +# df.columns[1][2:] + diff --git a/q01_rename_columns/tests/__pycache__/__init__.cpython-36.pyc b/q01_rename_columns/tests/__pycache__/__init__.cpython-36.pyc index ee14684..fecdaa0 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..3b81fc6 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..aac806a 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..0be30fa 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..103abbf 100644 --- a/q02_country_operations/build.py +++ b/q02_country_operations/build.py @@ -1,9 +1,19 @@ +# %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): + +def q02_country_operations(OlympicsDF): + OlympicsDF['Country_Name'] = OlympicsDF['Country'] + + for index, value in enumerate(OlympicsDF['Country_Name']): + OlympicsDF['Country_Name'][index] = value.replace(value, OlympicsDF['Country_Name'].str.strip()[index].split('\xa0')[0]) + + 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..ed02112 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..909612a 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..1528742 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..643786a 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..ca7b4da 100644 --- a/q03_better_event/build.py +++ b/q03_better_event/build.py @@ -1,13 +1,33 @@ +# %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.empty + for i in range(len(OlympicsDF)): + if OlympicsDF.iloc[i, 5] > OlympicsDF.iloc[i, 10]: + #summer + OlympicsDF['BetterEvent'][i] = 'Summer' + if OlympicsDF.iloc[i, 5] < OlympicsDF.iloc[i, 10]: + #winter + OlympicsDF['BetterEvent'][i] = 'Winter' + if OlympicsDF.iloc[i, 5] == OlympicsDF.iloc[i, 10]: + #both + OlympicsDF['BetterEvent'][i] = 'Both' + return OlympicsDF +df = q03_better_event(OlympicsDF) +df.BetterEvent.value_counts().max() +df.shape +df.BetterEvent.value_counts().max() + diff --git a/q03_better_event/tests/__pycache__/__init__.cpython-36.pyc b/q03_better_event/tests/__pycache__/__init__.cpython-36.pyc index 3988395..1f97f55 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..5c11771 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..499d1dc 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..2c24368 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..3aa6648 100644 --- a/q04_find_top_10/build.py +++ b/q04_find_top_10/build.py @@ -1,8 +1,26 @@ +# %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): + + total_summer = OlympicsDF.sort_values(by=Total_Summer, ascending=False)['Country_Name'].iloc[1:11] + total_winter = OlympicsDF.sort_values(by=Total_Winter, ascending=False)['Country_Name'].iloc[1:11] + total = OlympicsDF.sort_values(by=Total, ascending=False)['Country_Name'].iloc[1:11] + common = set(total_summer) & set(total_winter) & set(total) + return total_summer, total_winter, total, common + +Top10Summer,Top10Winter, Top10, Common =q04_find_top_10(OlympicsDF,'Total_Summer', 'Total_Winter','Total') +Top10Winter +OlympicsDF.sort_values(by='Total_Winter', ascending=False)[['Total_Winter', 'Country_Name']].iloc[1:11] + + + + + + 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..e4f0d87 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..c153999 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..2e5237c 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..a4543ff 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..1c58df2 100644 --- a/q05_top_10_plotting/build.py +++ b/q05_top_10_plotting/build.py @@ -1,13 +1,27 @@ +# %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): + Top10Summer = OlympicsDF.loc[OlympicsDF.Country_Name.isin(Top10Summer)].loc[:,['Country_Name', 'Total']] + Top10Summer.plot(x='Country_Name', y='Total',kind='bar') + + Top10Winter = OlympicsDF.loc[OlympicsDF.Country_Name.isin(Top10Winter)].loc[:,['Country_Name', 'Total']] + Top10Winter.plot(x='Country_Name', y='Total',kind='bar') + + Top10 = OlympicsDF.loc[OlympicsDF.Country_Name.isin(Top10)].loc[:,['Country_Name', 'Total']] + Top10.plot(x='Country_Name', y='Total',kind='bar') + plt.show() + +q05_top_10_plotting(OlympicsDF,Top10Summer,Top10Winter, Top10) + 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..2db8d75 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..10ead1c 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..4b17797 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..7a99e7d 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..93a5c6e 100644 --- a/q06_golden_winner/build.py +++ b/q06_golden_winner/build.py @@ -1,10 +1,43 @@ +# %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): + +# Top10Summer = OlympicsDF.loc[OlympicsDF.Country_Name.isin(Top10Summer)].loc[:,['Country_Name', 'Total']] + + Top10Summer = OlympicsDF.loc[OlympicsDF.Country_Name.isin(Top10Summer)] + Top10Winter = OlympicsDF.loc[OlympicsDF.Country_Name.isin(Top10Winter)] + Top10 = OlympicsDF.loc[OlympicsDF.Country_Name.isin(Top10)] + + Top10Summer['gold_s_ratio'] = Top10Summer['Gold_Summer'] + Top10Summer['gold_s_ratio'] = Top10Summer['Gold_Summer'] / Top10Summer['Total_Summer'] + + Top10Winter['gold_w_ratio'] = Top10Winter['Gold_Winter'] + Top10Winter['gold_w_ratio'] = Top10Winter['Gold_Winter'] / Top10Winter['Total_Winter'] + + Top10['gold_b_ratio'] = Top10['Gold_Total'] + Top10['gold_b_ratio'] = Top10['Gold_Total'] / Top10['Total'] + + gold_s_ratio = Top10Summer.loc[Top10Summer['gold_s_ratio'].idxmax()]['Country_Name'] + gold_w_ratio = Top10Winter.loc[Top10Winter['gold_w_ratio'].idxmax()]['Country_Name'] + gold_b_ratio = Top10.loc[Top10['gold_b_ratio'].idxmax()]['Country_Name'] + + return gold_s_ratio, gold_w_ratio, gold_b_ratio +# Top10Winter = OlympicsDF.loc[OlympicsDF.Country_Name.isin(Top10Winter)] +# Top10Winter['gold_w_ratio'] = Top10Winter['Gold_Winter'] +# Top10Winter['gold_w_ratio'] = Top10Winter['Gold_Winter'] / Top10Winter['Total_Winter'] +# Top10Winter +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..6a664ea 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..e4de804 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