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

csvPath = './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(csvPath)





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.
22 changes: 20 additions & 2 deletions q02_country_operations/build.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,26 @@
# %load q02_country_operations/build.py
# default imports
from greyatomlib.olympics_project_new.q01_rename_columns.build import q01_rename_columns
import pandas as pd

#Previous Functions
path = "./data/olympics.csv"
OlympicsDF=q01_rename_columns(path)
path = './data/olympics.csv'
OlympicsDF=q01_rename_columns(path)

def q02_country_operations(dataframe=OlympicsDF):
dataframe['Country_Name'] = dataframe.Country.str.split('(').str[0].str.strip()

#dataframe.Country.str.split('(') - splits the column into 2 columns viz. country and its short name
#.str[0] - takes the first column only discarding the country short names column
#.str.strip() - removes the extra space at the end of our country column

return dataframe

#Call to the function
q02_country_operations(OlympicsDF).head(150)






Expand Down
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.
19 changes: 18 additions & 1 deletion q03_better_event/build.py
Original file line number Diff line number Diff line change
@@ -1,12 +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
import pandas as pd
#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']=''

OlympicsDF.loc[OlympicsDF['Total_Summer']>OlympicsDF['Total_Winter'],'BetterEvent']='Summer'
OlympicsDF.loc[OlympicsDF['Total_Summer']<OlympicsDF['Total_Winter'],'BetterEvent']='Winter'
OlympicsDF.loc[OlympicsDF['Total_Summer']==OlympicsDF['Total_Winter'],'BetterEvent']='Both'

return OlympicsDF

#Call to the function-
q03_better_event(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.
27 changes: 25 additions & 2 deletions q04_find_top_10/build.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,31 @@
# %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)
OlympicsDF=q03_better_event(OlympicsDF)

def q04_find_top_10(Dataset, col1, col2, col3):

#Getting the indices of top 10 countries event wise(viz. Summer, Winter, Total) and storing it in a variable.
#Dataset.iloc[0:-1,:] --> Excludes the last row which gives the total count. Hence to be excluded in analysis.
summer_index = Dataset.iloc[0:-1,:].sort_values(by=[col1],ascending=False).head(10).index
winter_index = Dataset.iloc[0:-1,:].sort_values(by=[col2],ascending=False).head(10).index
total_index = Dataset.iloc[0:-1,:].sort_values(by=[col3],ascending=False).head(10).index

#Stores common index in all the above 3 lists
intersect_index = summer_index.intersection(winter_index).intersection(total_index)

#Separate list to store countries for each event.
summer_top_10_Countries = Dataset.loc[summer_index,'Country_Name']
winter_top_10_Countries = Dataset.loc[winter_index,'Country_Name']
total_top_10_Countries = Dataset.loc[total_index,'Country_Name']
common_Countries = Dataset.loc[intersect_index,'Country_Name']

return summer_top_10_Countries,winter_top_10_Countries,total_top_10_Countries,common_Countries

#Call to the function -
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.
23 changes: 21 additions & 2 deletions q05_top_10_plotting/build.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,34 @@
# %load q05_top_10_plotting/build.py
# default imports
import matplotlib.pyplot as plt
import pandas as pd
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(Dataset,col1=Top10Summer,col2=Top10Winter,col3=Top10):

Dataset[Dataset['Country_Name'].isin(col1)].plot(x='Country_Name',y='Total_Summer',kind='bar')
plt.title('Top 10 Summer')
plt.xlabel('Country Name')
plt.ylabel('Total Medals')

Dataset[Dataset['Country_Name'].isin(col2)].plot(x='Country_Name',y='Total_Winter',kind='bar')
plt.title('Top 10 Winter')
plt.xlabel('Country Name')
plt.ylabel('Total Medals')

Dataset[Dataset['Country_Name'].isin(col3)].plot(x='Country_Name',y='Total',kind='bar')
plt.title('Top 10')
plt.xlabel('Country Name')
plt.ylabel('Total Medals')
plt.show()

#Call to the function
q05_top_10_plotting(OlympicsDF,Top10Summer,Top10Winter,Top10)

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.
21 changes: 20 additions & 1 deletion q06_golden_winner/build.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,29 @@
# %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')

#Purposely not passing paramters inside and hadcoding instead to avoid confusion while revising.
def q06_golden_winner(Dataset=OlympicsDF,list1=Top10Summer,list2=Top10Winter,list3=Top10):

Summer = OlympicsDF[OlympicsDF['Country_Name'].isin(Top10Summer)].loc[:,['Country_Name','Gold_Summer','Total_Summer']]
Summer['Gold_Ratio']=Summer['Gold_Summer']/Summer['Total_Summer']
Best_Country_Summer = Summer.sort_values(by='Gold_Ratio',ascending=False).iloc[0,0]

Winter = OlympicsDF[OlympicsDF['Country_Name'].isin(Top10Winter)].loc[:,['Country_Name','Gold_Winter','Total_Winter']]
Winter['Gold_Ratio']=Winter['Gold_Winter']/Winter['Total_Winter']
Best_Country_Winter = Winter.sort_values(by='Gold_Ratio',ascending=False).iloc[0,0]

Total = OlympicsDF[OlympicsDF['Country_Name'].isin(Top10)].loc[:,['Country_Name','Gold_Total','Total']]
Total['Gold_Ratio']=Total['Gold_Total']/Total['Total']
Best_Country_Total = Total.sort_values(by='Gold_Ratio',ascending=False).iloc[0,0]

return Best_Country_Summer,Best_Country_Winter,Best_Country_Total

#Call to the function-
q06_golden_winner()

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.
38 changes: 37 additions & 1 deletion q07_unusual_performances/build.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,41 @@
# %load q07_unusual_performances/build.py
# default imports

#My Solution
import pandas as pd
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(Dataset, lower_percentile, higher_percentile):

Lower_Quantile = OlympicsDF['Total'].quantile(lower_percentile)
Higher_Quantile = OlympicsDF['Total'].quantile(higher_percentile)

OlympicsDF.drop(OlympicsDF.tail(1).index,inplace=True)

Better_Countries = OlympicsDF[OlympicsDF['Total']>Higher_Quantile]['Country_Name']
Worse_Countries = OlympicsDF[OlympicsDF['Total']<=Lower_Quantile]['Country_Name']

return Worse_Countries,Better_Countries




#Call to the function-
q07_unusual_performances(OlympicsDF,0.05,0.95)
#Solution that passed the test case
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
q07_unusual_performances(OlympicsDF,0.05,0.95)

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.