diff --git a/q01_plot_deliveries_by_team/build.py b/q01_plot_deliveries_by_team/build.py index d1dab11..0eab31a 100644 --- a/q01_plot_deliveries_by_team/build.py +++ b/q01_plot_deliveries_by_team/build.py @@ -1,3 +1,4 @@ +# %load q01_plot_deliveries_by_team/build.py import pandas as pd import numpy as np import matplotlib.pyplot as plt @@ -7,3 +8,12 @@ # Solution +def plot_deliveries_by_team(): + count=ipl_df.groupby(ipl_df['batting_team']).agg('count') + plt.bar(count.index,count['delivery']) + plt.title('Deliveries/teams') + plt.xlabel('batting_teams') + plt.ylabel('Deliveries') + plt.show() +plot_deliveries_by_team() + diff --git a/q02_plot_matches_by_team/build.py b/q02_plot_matches_by_team/build.py index ce53182..70803fb 100644 --- a/q02_plot_matches_by_team/build.py +++ b/q02_plot_matches_by_team/build.py @@ -1,3 +1,4 @@ +# %load q02_plot_matches_by_team/build.py import pandas as pd import numpy as np import matplotlib.pyplot as plt @@ -6,3 +7,14 @@ # Solution +def plot_matches_by_team(): + count=ipl_df.groupby(ipl_df['batting_team']).agg('nunique') + plt.bar(count.index,count['match_code']) + plt.title('count of matches/teams') + plt.xlabel('batting_teams') + plt.ylabel('count of matches') + plt.xticks(count.index,rotation=90) + plt.show() +plot_matches_by_team() + + diff --git a/q03_plot_innings_runs_histogram/build.py b/q03_plot_innings_runs_histogram/build.py index ce53182..7dbcf72 100644 --- a/q03_plot_innings_runs_histogram/build.py +++ b/q03_plot_innings_runs_histogram/build.py @@ -1,8 +1,21 @@ +# %load q03_plot_innings_runs_histogram/build.py import pandas as pd import numpy as np import matplotlib.pyplot as plt -plt.switch_backend('agg') +#plt.switch_backend('agg') ipl_df = pd.read_csv('data/ipl_dataset.csv', index_col=None) # Solution +def plot_innings_runs_histogram(): + i1=ipl_df[ipl_df['inning']==1] + x=i1.groupby(ipl_df['match_code']).agg('sum') + + i2=ipl_df[ipl_df['inning']==2] + y=i2.groupby(ipl_df['match_code']).agg('sum') + fig, axs = plt.subplots(1, 2, sharey=True) + axs[0].hist(x['runs']) + axs[1].hist(y['runs']) + fig.show() +plot_innings_runs_histogram() + diff --git a/q04_plot_runs_by_balls/build.py b/q04_plot_runs_by_balls/build.py index ce53182..be679e2 100644 --- a/q04_plot_runs_by_balls/build.py +++ b/q04_plot_runs_by_balls/build.py @@ -1,3 +1,4 @@ +# %load q04_plot_runs_by_balls/build.py import pandas as pd import numpy as np import matplotlib.pyplot as plt @@ -6,3 +7,11 @@ # Solution +def plot_runs_by_balls(): + bat=ipl_df.groupby(['batsman','match_code']).agg({'runs':sum,'delivery':'count'}) + plt.scatter(bat.delivery,bat.runs) + plt.xlabel('balls faced') + plt.ylabel('runs scored') + plt.show() +plot_runs_by_balls() +