From daf2cab083fd55e458123a94099d19eb780728dc Mon Sep 17 00:00:00 2001 From: tracedence Date: Thu, 20 Sep 2018 10:01:15 +0000 Subject: [PATCH 1/8] Done --- q01_read_csv_data_to_df/build.py | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/q01_read_csv_data_to_df/build.py b/q01_read_csv_data_to_df/build.py index 7af672f..6562a62 100644 --- a/q01_read_csv_data_to_df/build.py +++ b/q01_read_csv_data_to_df/build.py @@ -1,8 +1,20 @@ +# %load q01_read_csv_data_to_df/build.py # Default Imports import pandas as pd # Path has been given to you already to use in function. -path = "data/ipl_dataset.csv" +path = 'data/ipl_dataset.csv' # Solution +def read_csv_data_to_df(path): + + #returning dataFrame when reding csv file + df = pd.read_csv(path) + + return df + +read_csv_data_to_df(path) + + + From aa67b71a23a2072df18a11a871d67873bf31ea98 Mon Sep 17 00:00:00 2001 From: tracedence Date: Thu, 20 Sep 2018 10:23:19 +0000 Subject: [PATCH 2/8] Done --- q02_get_unique_values/build.py | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/q02_get_unique_values/build.py b/q02_get_unique_values/build.py index a98550a..c8d87e9 100644 --- a/q02_get_unique_values/build.py +++ b/q02_get_unique_values/build.py @@ -1,6 +1,21 @@ +# %load q02_get_unique_values/build.py from greyatomlib.pandas_project.q01_read_csv_data_to_df.build import read_csv_data_to_df - +import pandas as pd # You have been given the dataset already in 'ipl_df'. -ipl_df = read_csv_data_to_df("data/ipl_dataset.csv") +ipl_df = read_csv_data_to_df('data/ipl_dataset.csv') #Solution +def get_unique_venues(): + + # get unique values from venue column + unique_venue = ipl_df['venue'].unique() + + return unique_venue + + +get_unique_venues() +#pd.set_option('display.max_row', 1000) +#pd.set_option('display.max_columns',10) + + + From d9833a8c7843504f374201395fd83c12da48b1b8 Mon Sep 17 00:00:00 2001 From: tracedence Date: Thu, 20 Sep 2018 10:34:55 +0000 Subject: [PATCH 3/8] Done --- q03_get_run_counts/build.py | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/q03_get_run_counts/build.py b/q03_get_run_counts/build.py index 07a05ac..1cee855 100644 --- a/q03_get_run_counts/build.py +++ b/q03_get_run_counts/build.py @@ -1,8 +1,19 @@ +# %load q03_get_run_counts/build.py # Default Imports from greyatomlib.pandas_project.q01_read_csv_data_to_df.build import read_csv_data_to_df # You have been given the dataset already in 'ipl_df'. -ipl_df = read_csv_data_to_df("./data/ipl_dataset.csv") +ipl_df = read_csv_data_to_df('./data/ipl_dataset.csv') # Solution +def get_run_counts(): + + # calculate the frequency of values in column runs + frequency_of_runs = ipl_df['runs'].value_counts() + + return frequency_of_runs + + +get_run_counts() + From 4954fbdada93bb012834ff155685ade861c708ee Mon Sep 17 00:00:00 2001 From: tracedence Date: Thu, 20 Sep 2018 11:42:07 +0000 Subject: [PATCH 4/8] Done --- q04_get_match_specific_df/build.py | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/q04_get_match_specific_df/build.py b/q04_get_match_specific_df/build.py index 37ec96a..e1cbea7 100644 --- a/q04_get_match_specific_df/build.py +++ b/q04_get_match_specific_df/build.py @@ -1,7 +1,24 @@ +# %load q04_get_match_specific_df/build.py from greyatomlib.pandas_project.q01_read_csv_data_to_df.build import read_csv_data_to_df # You have been given dataset already in 'ipl_df'. -ipl_df = read_csv_data_to_df("./data/ipl_dataset.csv") +ipl_df = read_csv_data_to_df('./data/ipl_dataset.csv') # Solution +def get_match_specific_df(match_code): + + #checking type of data in match_code + #print(type(ipl_df['match_code'][0])) + + #match_code == ipl_df['match_code'][0] #output is true + + # result of particular match_code + result = ipl_df[ipl_df['match_code']== match_code] + + return result + +match_code = 392203 +get_match_specific_df(match_code) + + From 88ba2670cc9e2e04343e38f5fa5ac9b448b89590 Mon Sep 17 00:00:00 2001 From: tracedence Date: Thu, 20 Sep 2018 11:54:22 +0000 Subject: [PATCH 5/8] Done --- q05_create_bowler_filter/build.py | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/q05_create_bowler_filter/build.py b/q05_create_bowler_filter/build.py index 5c15aaa..434c0a3 100644 --- a/q05_create_bowler_filter/build.py +++ b/q05_create_bowler_filter/build.py @@ -1,7 +1,21 @@ +# %load q05_create_bowler_filter/build.py # Default imports from greyatomlib.pandas_project.q01_read_csv_data_to_df.build import read_csv_data_to_df # You have been given dataset already in 'ipl_df'. -ipl_df = read_csv_data_to_df("./data/ipl_dataset.csv") +ipl_df = read_csv_data_to_df('./data/ipl_dataset.csv') # Solution +def create_bowler_filter(bowler_name): + + #checking whether type of data in bowler column same or not + #print(ipl_df['bowler'][0]== bowler_name ) + + # returning filter result + result = ipl_df['bowler'] == bowler_name + + return result +bowler_name = 'I Sharma' +create_bowler_filter(bowler_name) + + From f2491c06edc901a439765f362a8fda63eb5be8fc Mon Sep 17 00:00:00 2001 From: tracedence Date: Thu, 20 Sep 2018 15:12:52 +0000 Subject: [PATCH 6/8] Done --- q06_get_match_innings_runs/build.py | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/q06_get_match_innings_runs/build.py b/q06_get_match_innings_runs/build.py index d938fc2..3c2a0f3 100644 --- a/q06_get_match_innings_runs/build.py +++ b/q06_get_match_innings_runs/build.py @@ -1,10 +1,21 @@ +# %load q06_get_match_innings_runs/build.py # Default Imports from greyatomlib.pandas_project.q01_read_csv_data_to_df.build import read_csv_data_to_df - +import pandas as pd # You have been given dataset already in 'ipl_df'. -ipl_df = read_csv_data_to_df("data/ipl_dataset.csv") +ipl_df = read_csv_data_to_df('data/ipl_dataset.csv') + +#pd.set_option('display.max_columns', 30) +def get_match_innings_runs(): + + df = (ipl_df.groupby(['match_code', 'inning']).sum())['runs'] + + return df + + +get_match_innings_runs() + -# Solution From 5e6ed4f404d0b712789f171492c15247265627f1 Mon Sep 17 00:00:00 2001 From: tracedence Date: Fri, 21 Sep 2018 07:32:26 +0000 Subject: [PATCH 7/8] Done --- q06_get_match_innings_runs/build.py | 4 ++-- q07_get_run_counts_by_match/build.py | 16 ++++++++++++++-- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/q06_get_match_innings_runs/build.py b/q06_get_match_innings_runs/build.py index 3c2a0f3..5f9f819 100644 --- a/q06_get_match_innings_runs/build.py +++ b/q06_get_match_innings_runs/build.py @@ -8,12 +8,12 @@ #pd.set_option('display.max_columns', 30) def get_match_innings_runs(): - df = (ipl_df.groupby(['match_code', 'inning']).sum())['runs'] + df = (ipl_df.groupby(['match_code', 'inning']).sum()) return df -get_match_innings_runs() +get_match_innings_runs().sort_values(ascending = False) diff --git a/q07_get_run_counts_by_match/build.py b/q07_get_run_counts_by_match/build.py index a18e534..a0ad505 100644 --- a/q07_get_run_counts_by_match/build.py +++ b/q07_get_run_counts_by_match/build.py @@ -1,7 +1,19 @@ +# %load q07_get_run_counts_by_match/build.py # Default Imports from greyatomlib.pandas_project.q01_read_csv_data_to_df.build import read_csv_data_to_df - +import pandas as pd # You have been give the dataset already in 'ipl_df'. -ipl_df = read_csv_data_to_df("./data/ipl_dataset.csv") +ipl_df = read_csv_data_to_df('./data/ipl_dataset.csv') # Solution +def get_runs_counts_by_match(): + + ipl_df1 = ipl_df[['match_code','runs','batsman']] + + pivot_df = pd.pivot_table(ipl_df1, values = ['runs'], index = ['match_code'], columns = ['runs'], aggfunc = 'count') + + return pivot_df +get_runs_counts_by_match() + + + From 836638a050d779042c5a1fc086f59f72e31a6f74 Mon Sep 17 00:00:00 2001 From: tracedence Date: Fri, 21 Sep 2018 09:16:04 +0000 Subject: [PATCH 8/8] Done --- q07_get_run_counts_by_match/build.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/q07_get_run_counts_by_match/build.py b/q07_get_run_counts_by_match/build.py index a0ad505..281c71a 100644 --- a/q07_get_run_counts_by_match/build.py +++ b/q07_get_run_counts_by_match/build.py @@ -8,8 +8,10 @@ # Solution def get_runs_counts_by_match(): + # create new dataframe of following columns ipl_df1 = ipl_df[['match_code','runs','batsman']] + # create a pivot table pivot_df = pd.pivot_table(ipl_df1, values = ['runs'], index = ['match_code'], columns = ['runs'], aggfunc = 'count') return pivot_df