diff --git a/q01_plot_deliveries_by_team/build.py b/q01_plot_deliveries_by_team/build.py index d1dab11..829b246 100644 --- a/q01_plot_deliveries_by_team/build.py +++ b/q01_plot_deliveries_by_team/build.py @@ -1,9 +1,19 @@ +# %load q01_plot_deliveries_by_team/build.py import pandas as pd import numpy as np import matplotlib.pyplot as plt plt.switch_backend('agg') + ipl_df = pd.read_csv('data/ipl_dataset.csv', index_col=None) # Solution +def plot_deliveries_by_team(ipl_df=ipl_df): + ipl_df['batting_team'].value_counts().plot.bar() +plot_deliveries_by_team() + + + + + diff --git a/q02_plot_matches_by_team/build.py b/q02_plot_matches_by_team/build.py index ce53182..c51f198 100644 --- a/q02_plot_matches_by_team/build.py +++ b/q02_plot_matches_by_team/build.py @@ -1,8 +1,16 @@ +# %load q02_plot_matches_by_team/build.py import pandas as pd import numpy as np import matplotlib.pyplot as plt plt.switch_backend('agg') ipl_df = pd.read_csv('data/ipl_dataset.csv', index_col=None) +def plot_matches_by_team(): + ipl_df.groupby('batting_team').agg({'match_code': pd.Series.nunique}).plot.bar() + +plot_matches_by_team() # Solution + + + diff --git a/q03_plot_innings_runs_histogram/build.py b/q03_plot_innings_runs_histogram/build.py index ce53182..3c307f2 100644 --- a/q03_plot_innings_runs_histogram/build.py +++ b/q03_plot_innings_runs_histogram/build.py @@ -1,3 +1,4 @@ +# %load q03_plot_innings_runs_histogram/build.py import pandas as pd import numpy as np import matplotlib.pyplot as plt @@ -6,3 +7,16 @@ # Solution +def plot_innings_runs_histogram(): + inning_wise_runs = ipl_df.groupby(['match_code', 'inning'])['runs'].sum() + first_inning_runs = inning_wise_runs[:,1] + second_inning_runs = inning_wise_runs[:,2] + fig, axs = plt.subplots(1, 2, sharey=True, tight_layout=True) + + axs[0].hist(first_inning_runs) + axs[1].hist(second_inning_runs) + + return + + + diff --git a/q04_plot_runs_by_balls/build.py b/q04_plot_runs_by_balls/build.py index ce53182..d331a81 100644 --- a/q04_plot_runs_by_balls/build.py +++ b/q04_plot_runs_by_balls/build.py @@ -1,8 +1,19 @@ +# %load q04_plot_runs_by_balls/build.py import pandas as pd import numpy as np import matplotlib.pyplot as plt plt.switch_backend('agg') ipl_df = pd.read_csv('data/ipl_dataset.csv', index_col=None) +def plot_runs_by_balls(): + balls_played_by_player = ipl_df.groupby(['match_code','batsman'])['delivery'].agg('count') + runs_made_by_player = ipl_df.groupby(['match_code','batsman'])['runs'].agg('sum') + plt.scatter(balls_played_by_player, runs_made_by_player) + + return # Solution + + + +