From 5e2819fe36a0fb4a162a67e490192e354da361a6 Mon Sep 17 00:00:00 2001 From: nehatanwani Date: Wed, 5 Dec 2018 05:42:13 +0000 Subject: [PATCH 1/4] Done --- q01_plot_deliveries_by_team/build.py | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) 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() + + + From ca8004b855754259bb28f22027ca2656e664e469 Mon Sep 17 00:00:00 2001 From: nehatanwani Date: Wed, 5 Dec 2018 05:44:06 +0000 Subject: [PATCH 2/4] Done --- q02_plot_matches_by_team/build.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) 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() + From 2802b6ba11c64acdb4aaf997c55c56a5374338d2 Mon Sep 17 00:00:00 2001 From: nehatanwani Date: Wed, 5 Dec 2018 05:47:01 +0000 Subject: [PATCH 3/4] Done --- q03_plot_innings_runs_histogram/build.py | 26 ++++++++++++++++++++++++ 1 file changed, 26 insertions(+) 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() + From 46c136c9c0d9d8ae4c8fbbfde2035b23ff595081 Mon Sep 17 00:00:00 2001 From: nehatanwani Date: Wed, 5 Dec 2018 05:48:18 +0000 Subject: [PATCH 4/4] Done --- q04_plot_runs_by_balls/build.py | 9 +++++++++ 1 file changed, 9 insertions(+) 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() + +