Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added __pycache__/__init__.cpython-36.pyc
Binary file not shown.
Binary file modified q01_rename_columns/__pycache__/__init__.cpython-36.pyc
Binary file not shown.
Binary file modified q01_rename_columns/__pycache__/build.cpython-36.pyc
Binary file not shown.
25 changes: 25 additions & 0 deletions q01_rename_columns/build.py
Original file line number Diff line number Diff line change
@@ -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







Binary file modified q01_rename_columns/tests/__pycache__/__init__.cpython-36.pyc
Binary file not shown.
Binary file modified q01_rename_columns/tests/__pycache__/test.cpython-36.pyc
Binary file not shown.
Binary file modified q02_country_operations/__pycache__/__init__.cpython-36.pyc
Binary file not shown.
Binary file modified q02_country_operations/__pycache__/build.cpython-36.pyc
Binary file not shown.
31 changes: 27 additions & 4 deletions q02_country_operations/build.py
Original file line number Diff line number Diff line change
@@ -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]



Binary file modified q02_country_operations/tests/__pycache__/__init__.cpython-36.pyc
Binary file not shown.
Binary file modified q02_country_operations/tests/__pycache__/test.cpython-36.pyc
Binary file not shown.
Binary file modified q03_better_event/__pycache__/__init__.cpython-36.pyc
Binary file not shown.
Binary file modified q03_better_event/__pycache__/build.cpython-36.pyc
Binary file not shown.
20 changes: 19 additions & 1 deletion q03_better_event/build.py
Original file line number Diff line number Diff line change
@@ -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








Expand Down
Binary file modified q03_better_event/tests/__pycache__/__init__.cpython-36.pyc
Binary file not shown.
Binary file modified q03_better_event/tests/__pycache__/test.cpython-36.pyc
Binary file not shown.
Binary file modified q04_find_top_10/__pycache__/__init__.cpython-36.pyc
Binary file not shown.
Binary file modified q04_find_top_10/__pycache__/build.cpython-36.pyc
Binary file not shown.
21 changes: 20 additions & 1 deletion q04_find_top_10/build.py
Original file line number Diff line number Diff line change
@@ -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')





Binary file modified q04_find_top_10/tests/__pycache__/__init__.cpython-36.pyc
Binary file not shown.
Binary file modified q04_find_top_10/tests/__pycache__/test.cpython-36.pyc
Binary file not shown.
Binary file modified q05_top_10_plotting/__pycache__/__init__.cpython-36.pyc
Binary file not shown.
Binary file modified q05_top_10_plotting/__pycache__/build.cpython-36.pyc
Binary file not shown.
24 changes: 23 additions & 1 deletion q05_top_10_plotting/build.py
Original file line number Diff line number Diff line change
@@ -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()



Expand Down
Binary file modified q05_top_10_plotting/tests/__pycache__/__init__.cpython-36.pyc
Binary file not shown.
Binary file modified q05_top_10_plotting/tests/__pycache__/test.cpython-36.pyc
Binary file not shown.
Binary file modified q06_golden_winner/__pycache__/__init__.cpython-36.pyc
Binary file not shown.
Binary file modified q06_golden_winner/__pycache__/build.cpython-36.pyc
Binary file not shown.
18 changes: 17 additions & 1 deletion q06_golden_winner/build.py
Original file line number Diff line number Diff line change
@@ -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



Binary file modified q06_golden_winner/tests/__pycache__/__init__.cpython-36.pyc
Binary file not shown.
Binary file modified q06_golden_winner/tests/__pycache__/test.cpython-36.pyc
Binary file not shown.
Binary file modified q07_unusual_performances/__pycache__/__init__.cpython-36.pyc
Binary file not shown.
Binary file modified q07_unusual_performances/__pycache__/build.cpython-36.pyc
Binary file not shown.
18 changes: 17 additions & 1 deletion q07_unusual_performances/build.py
Original file line number Diff line number Diff line change
@@ -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






Binary file modified q07_unusual_performances/tests/__pycache__/__init__.cpython-36.pyc
Binary file not shown.
Binary file modified q07_unusual_performances/tests/__pycache__/test.cpython-36.pyc
Binary file not shown.