diff --git a/q01_read_csv_data_to_df/build.py b/q01_read_csv_data_to_df/build.py index 7af672f..3338daf 100644 --- a/q01_read_csv_data_to_df/build.py +++ b/q01_read_csv_data_to_df/build.py @@ -1,8 +1,13 @@ -# Default Imports +#%load q01_read_csv_data_to_df/build.py + import pandas as pd +path='./data/ipl_dataset.csv' +def read_csv_data_to_df(path): + df=pd.read_csv(path) + + return df + + -# Path has been given to you already to use in function. -path = "data/ipl_dataset.csv" -# Solution diff --git a/q02_get_unique_values/build.py b/q02_get_unique_values/build.py index a98550a..700ef66 100644 --- a/q02_get_unique_values/build.py +++ b/q02_get_unique_values/build.py @@ -1,6 +1,18 @@ -from greyatomlib.pandas_project.q01_read_csv_data_to_df.build import read_csv_data_to_df +#%load q02_get_unique_values/build.py + +import pandas as pd + +path='./data/ipl_dataset.csv' + +def get_unique_venues(): + df=pd.read_csv(path) + + venue=df.venue.unique() + + return venue + + + + -# You have been given the dataset already in 'ipl_df'. -ipl_df = read_csv_data_to_df("data/ipl_dataset.csv") -#Solution diff --git a/q03_get_run_counts/build.py b/q03_get_run_counts/build.py index 07a05ac..161e6c6 100644 --- a/q03_get_run_counts/build.py +++ b/q03_get_run_counts/build.py @@ -1,8 +1,14 @@ -# Default Imports -from greyatomlib.pandas_project.q01_read_csv_data_to_df.build import read_csv_data_to_df +#%load q03_get_run_counts/build.py -# You have been given the dataset already in 'ipl_df'. -ipl_df = read_csv_data_to_df("./data/ipl_dataset.csv") +import pandas as pd +path='./data/ipl_dataset.csv' + +def get_run_counts(): + df=pd.read_csv(path) + + grp=df.groupby(df.runs)['runs'].count() + + #print(type(grp)) + return grp -# Solution diff --git a/q04_get_match_specific_df/build.py b/q04_get_match_specific_df/build.py index 37ec96a..fa8d260 100644 --- a/q04_get_match_specific_df/build.py +++ b/q04_get_match_specific_df/build.py @@ -1,7 +1,22 @@ -from greyatomlib.pandas_project.q01_read_csv_data_to_df.build import read_csv_data_to_df +# %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 + +import numpy as np +import pandas as pd +ifl_df=pd.read_csv('./data/ipl_dataset.csv') + + +def get_match_specific_df(match_code): + + + + #df=ifl_df[(ifl_df['match_code']==match_code)] + df=ifl_df[ifl_df.match_code==match_code] + return df + +get_match_specific_df(598057) + + -# You have been given dataset already in 'ipl_df'. -ipl_df = read_csv_data_to_df("./data/ipl_dataset.csv") -# Solution diff --git a/q05_create_bowler_filter/build.py b/q05_create_bowler_filter/build.py index 5c15aaa..d7fe921 100644 --- a/q05_create_bowler_filter/build.py +++ b/q05_create_bowler_filter/build.py @@ -1,7 +1,16 @@ -# Default imports -from greyatomlib.pandas_project.q01_read_csv_data_to_df.build import read_csv_data_to_df +#%load q05_create_bowler_filter/build.py +import pandas as pd +import numpy as np + +ifl_df=pd.read_csv('./data/ipl_dataset.csv') + +def create_bowler_filter(bowler): + + bl=ifl_df['bowler'] + + return bl==bowler + + + -# You have been given dataset already in 'ipl_df'. -ipl_df = read_csv_data_to_df("./data/ipl_dataset.csv") -# Solution diff --git a/q06_get_match_innings_runs/build.py b/q06_get_match_innings_runs/build.py index d938fc2..96ff497 100644 --- a/q06_get_match_innings_runs/build.py +++ b/q06_get_match_innings_runs/build.py @@ -1,10 +1,14 @@ -# Default Imports -from greyatomlib.pandas_project.q01_read_csv_data_to_df.build import read_csv_data_to_df +#%load q06_get_match_innings_runs/build.py +import pandas as pd +import numpy as np -# You have been given dataset already in 'ipl_df'. -ipl_df = read_csv_data_to_df("data/ipl_dataset.csv") +ifl_df=pd.read_csv('./data/ipl_dataset.csv') -# Solution +def get_match_innings_runs(): + + ifl_df2=ifl_df.groupby(['match_code','inning'])['runs'].sum() + + return ifl_df2 diff --git a/q07_get_run_counts_by_match/build.py b/q07_get_run_counts_by_match/build.py index a18e534..35d4f75 100644 --- a/q07_get_run_counts_by_match/build.py +++ b/q07_get_run_counts_by_match/build.py @@ -1,7 +1,19 @@ -# Default Imports -from greyatomlib.pandas_project.q01_read_csv_data_to_df.build import read_csv_data_to_df +#%load q07_get_run_counts_by_match/build.py + + +import pandas as pd +import numpy as np + +df=pd.read_csv('./data/ipl_dataset.csv') +#df.columns +def get_runs_counts_by_match(): + + df1=df.pivot_table(index='match_code',columns='runs',values='batsman',aggfunc='count') + + return df1 + +get_runs_counts_by_match() +# gr=df.groupby('match_code') +# gr['runs'].sum() -# You have been give the dataset already in 'ipl_df'. -ipl_df = read_csv_data_to_df("./data/ipl_dataset.csv") -# Solution