diff --git a/q01_plot_deliveries_by_team/build.py b/q01_plot_deliveries_by_team/build.py index d1dab11..606f78f 100644 --- a/q01_plot_deliveries_by_team/build.py +++ b/q01_plot_deliveries_by_team/build.py @@ -1,9 +1,23 @@ +#%load q01_plot_deliveries_by_team/build.py +# %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') +import matplotlib.pyplot as plt; plt.rcdefaults() +#plt.switch_backend('agg') ipl_df = pd.read_csv('data/ipl_dataset.csv', index_col=None) # Solution +def plot_deliveries_by_team(): + ser = ipl_df.groupby(['batting_team']).count()['match_code'] + y_pos = np.arange(len(ser)) + plt.bar(y_pos, ser, align='center', alpha=0.5) + x_pos = ser.index + plt.xticks(y_pos, x_pos, rotation=90) + plt.ylabel('Deliveries') + plt.title('Teams Vs Deliveries') + plt.show() + + + diff --git a/q02_plot_matches_by_team/build.py b/q02_plot_matches_by_team/build.py index ce53182..fac30d8 100644 --- a/q02_plot_matches_by_team/build.py +++ b/q02_plot_matches_by_team/build.py @@ -1,3 +1,5 @@ +#%load q02_plot_matches_by_team/build.py +# %load q02_plot_matches_by_team/build.py import pandas as pd import numpy as np import matplotlib.pyplot as plt @@ -6,3 +8,13 @@ # Solution +def plot_matches_by_team(): + ser = ipl_df.groupby(['batting_team']).count()['match_code'] + y_pos = np.arange(len(ser)) + plt.bar(y_pos, ser, align='center', alpha=0.5) + x_pos = ser.index + plt.xticks(y_pos, x_pos, rotation=90) + plt.ylabel('Deliveries') + plt.title('Teams Vs Deliveries') + plt.show() + diff --git a/q03_plot_innings_runs_histogram/build.py b/q03_plot_innings_runs_histogram/build.py index ce53182..a76ac14 100644 --- a/q03_plot_innings_runs_histogram/build.py +++ b/q03_plot_innings_runs_histogram/build.py @@ -1,3 +1,5 @@ +#%load q03_plot_innings_runs_histogram/build.py +# %load q03_plot_innings_runs_histogram/build.py import pandas as pd import numpy as np import matplotlib.pyplot as plt @@ -6,3 +8,27 @@ # Solution +def get_data(): + first_inning = ipl_df[ipl_df['inning'] == 1] + second_inning = ipl_df[ipl_df['inning'] == 2] + + fi_df = pd.DataFrame( + first_inning.groupby(['match_code']).sum()['runs']) + se_df = pd.DataFrame( + second_inning.groupby('match_code').sum()['runs']) + + return fi_df, se_df + +def plot_innings_runs_histogram(): + f,s = get_data() + fig, (ax1, ax2) = plt.subplots(1,2) + ax1.hist(f, bins=12) + ax1.set_title('First Inning Runs') + plt.xticks(rotation=90) + ax2.hist(s, bins=12) + ax2.set_title('Second Inning Runs') + plt.xticks(rotation=90) + plt.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..c0c5ba5 100644 --- a/q04_plot_runs_by_balls/build.py +++ b/q04_plot_runs_by_balls/build.py @@ -1,3 +1,5 @@ +#%load q04_plot_runs_by_balls/build.py +# %load q04_plot_runs_by_balls/build.py import pandas as pd import numpy as np import matplotlib.pyplot as plt @@ -6,3 +8,10 @@ # Solution +def plot_runs_by_balls(): + run_details = ipl_df.groupby(['match_code', 'batsman']).agg({'runs': ['count', 'sum']})['runs'] + plt.scatter(run_details['count'], run_details['sum']) + plt.show() +plot_runs_by_balls() + +