diff --git a/q01_read_csv_data_to_df/build.py b/q01_read_csv_data_to_df/build.py index 7af672f..0d78f8c 100644 --- a/q01_read_csv_data_to_df/build.py +++ b/q01_read_csv_data_to_df/build.py @@ -1,8 +1,15 @@ +# %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): + return pd.read_csv(path) + +path +read_csv_data_to_df(path) + diff --git a/q02_get_unique_values/build.py b/q02_get_unique_values/build.py index a98550a..c30e318 100644 --- a/q02_get_unique_values/build.py +++ b/q02_get_unique_values/build.py @@ -1,6 +1,12 @@ +# %load q02_get_unique_values/build.py 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_unique_venues(): + return ipl_df.venue.unique() +get_unique_venues() + + diff --git a/q03_get_run_counts/build.py b/q03_get_run_counts/build.py index 07a05ac..366cbf1 100644 --- a/q03_get_run_counts/build.py +++ b/q03_get_run_counts/build.py @@ -1,8 +1,15 @@ +# %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(): + return ipl_df.runs.value_counts() + + + + diff --git a/q04_get_match_specific_df/build.py b/q04_get_match_specific_df/build.py index 37ec96a..75312af 100644 --- a/q04_get_match_specific_df/build.py +++ b/q04_get_match_specific_df/build.py @@ -1,7 +1,20 @@ +# %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(some_value): + df=ipl_df + return df.loc[df['match_code'] == some_value] + + + +df=ipl_df +some_value=598057 +df +df.loc[df['match_code'] == some_value] + + diff --git a/q05_create_bowler_filter/build.py b/q05_create_bowler_filter/build.py index 5c15aaa..60bf3d4 100644 --- a/q05_create_bowler_filter/build.py +++ b/q05_create_bowler_filter/build.py @@ -1,7 +1,25 @@ +# %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 - +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') # Solution +def create_bowler_filter(some_value): + df=ipl_df + l=df['bowler'] == some_value + return l +df=ipl_df +some_value='I Sharma' +l=[df['bowler'] == some_value] + +import pandas as pd +s=pd.Series([l]) +s.head() +pd.Series([l]).cumsum() +l=[df['bowler'] == 'I Sharma'] + +pd.Series(l) + + diff --git a/q06_get_match_innings_runs/build.py b/q06_get_match_innings_runs/build.py index d938fc2..2763ee6 100644 --- a/q06_get_match_innings_runs/build.py +++ b/q06_get_match_innings_runs/build.py @@ -1,11 +1,28 @@ +# %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 # 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_innings_runs(): + df = ipl_df + return df.loc[:, ['runs']] + #l=df.groupby(['match_code','inning','runs']) + #return l + +df=ipl_df +df.loc[:, ['runs','match_code', 'inning']] + +d=get_match_innings_runs() +d.sum() +type(d.sum()) +l=df.groupby(['match_code','inning','runs']) +l.sum() + + diff --git a/q07_get_run_counts_by_match/build.py b/q07_get_run_counts_by_match/build.py index a18e534..672a508 100644 --- a/q07_get_run_counts_by_match/build.py +++ b/q07_get_run_counts_by_match/build.py @@ -1,7 +1,18 @@ +# %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 +import numpy as np # 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(): + table = pd.pivot_table(ipl_df, index=['match_code'],values=['runs'],columns=['total'],aggfunc=np.sum,fill_value=0) + return table.iloc[:,:-1] + + + + + +