diff --git a/q01_plot_deliveries_by_team/build.py b/q01_plot_deliveries_by_team/build.py index d1dab11..d89f891 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,14 @@ # Solution +def plot_deliveries_by_team(): + batting_team = ipl_df['batting_team'] + deliveries_by_team = batting_team.value_counts() + x_series = np.arange(len(deliveries_by_team.index)) + plt.bar(x_series, deliveries_by_team) + plt.xticks(x_series, deliveries_by_team.index.values, rotation=90) + 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..7f9103c 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,17 @@ # Solution +def plot_matches_by_team(): + matches_by_team = ipl_df[['batting_team', 'match_code']].groupby(['batting_team']).aggregate('nunique') + x_series = np.arange(len(matches_by_team.index)) + + plt.bar(x_series, matches_by_team['match_code']) + plt.xlabel('Team') + plt.ylabel('Matches Count') + + plt.xticks(x_series, matches_by_team.index.values, rotation=90) + plt.show() + print(matches_by_team) +plot_matches_by_team() + + diff --git a/q03_plot_innings_runs_histogram/build.py b/q03_plot_innings_runs_histogram/build.py index ce53182..336ee2c 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,13 @@ # Solution +def plot_innings_runs_histogram(): + per_match_runs = ipl_df[['match_code', 'inning']].groupby('inning').agg('sum') + plt.hist(per_match_runs) + plt.show() + print(per_match_runs) + +plot_innings_runs_histogram() + + + diff --git a/q04_plot_runs_by_balls/build.py b/q04_plot_runs_by_balls/build.py index ce53182..df51a99 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,15 @@ # Solution +def plot_runs_by_balls(): + group_by = ipl_df.groupby(['match_code', 'batsman']) + balls = group_by['runs'].count().rename('balls').reset_index() + runs = group_by['runs'].sum().rename('runs').reset_index() + df = pd.merge(balls, runs, on=['match_code', 'batsman']) + plt.scatter(x=df['runs'], y=df['balls']) + plt.xlabel('Count of Balls Played') + plt.ylabel('Total Runs Scored') + plt.show() +plot_runs_by_balls() + +