From a4a4b296a48cc61af12009e1887bc430b5ebd132 Mon Sep 17 00:00:00 2001 From: tracedence Date: Tue, 25 Sep 2018 11:23:11 +0000 Subject: [PATCH 1/5] Done --- q01_plot_deliveries_by_team/build.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/q01_plot_deliveries_by_team/build.py b/q01_plot_deliveries_by_team/build.py index d1dab11..f87e2eb 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,17 @@ # Solution +def plot_deliveries_by_team(): + + fig = plt.figure() + data = ipl_df.groupby('batting_team').count()['delivery'] + plt.plot(data.index, data.values) + plt.xticks(rotation = 30) + plt.show() + +plot_deliveries_by_team() + + + + + From 8a367030c12e507cb2d42861d123f938ac72a0db Mon Sep 17 00:00:00 2001 From: tracedence Date: Tue, 25 Sep 2018 11:27:10 +0000 Subject: [PATCH 2/5] Done --- q01_plot_deliveries_by_team/build.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/q01_plot_deliveries_by_team/build.py b/q01_plot_deliveries_by_team/build.py index f87e2eb..974b5b6 100644 --- a/q01_plot_deliveries_by_team/build.py +++ b/q01_plot_deliveries_by_team/build.py @@ -10,9 +10,16 @@ # Solution def plot_deliveries_by_team(): - fig = plt.figure() + #create figure for drawing data + fig = plt.figure() + + # group data by batting team and use count as aggregator, then select delivery column since result in the form of pandas data = ipl_df.groupby('batting_team').count()['delivery'] - plt.plot(data.index, data.values) + + # plot bar graph + plt.bar(data.index, data.values) + + # rotate ticks of x axis by 30 plt.xticks(rotation = 30) plt.show() From dfc3d09fc98d4a133ddfd359c5f91fd7f7e90b9e Mon Sep 17 00:00:00 2001 From: tracedence Date: Tue, 25 Sep 2018 12:48:03 +0000 Subject: [PATCH 3/5] Done --- q02_plot_matches_by_team/build.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/q02_plot_matches_by_team/build.py b/q02_plot_matches_by_team/build.py index ce53182..a440976 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,18 @@ # Solution +def plot_matches_by_team(): + #create empty canvas to draw + fig = plt.figure() + # groupby batting team then count unique and select match_code(as it uniquely identified matched played) + match_played = ipl_df.groupby('batting_team').nunique()['match_code'] + #plotting bar + plt.bar(match_played.index, match_played) + #rotating x ticks by -90 for easy reading team name + plt.xticks(rotation = -90) + plt.show() + +plot_matches_by_team() + + + From 03039faeeb80c0850253e552b0e24dbbee6943f9 Mon Sep 17 00:00:00 2001 From: tracedence Date: Tue, 25 Sep 2018 13:39:23 +0000 Subject: [PATCH 4/5] Done --- q03_plot_innings_runs_histogram/build.py | 33 ++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/q03_plot_innings_runs_histogram/build.py b/q03_plot_innings_runs_histogram/build.py index ce53182..9f77f86 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,35 @@ # Solution +def plot_inning_runs_histogram(): + # storing first inning data + first_inning_data = ipl_df[ipl_df['inning'] == 1] + + #storing second inning data + second_inning_data = ipl_df[ipl_df['inning']==2] + + # grouping first inning data by match code and then select 'runs' columns from it + first = first_inning_data.groupby('match_code').sum()['runs'] + + # grouping second inning data by match code and then select 'runs' column from it + second = second_inning_data.groupby('match_code').sum()['runs'] + + #creating figure to draw + fig = plt.figure() + + #creatng supplots in figure + fig, ax = plt.subplots(1,2) + + #drawing histogram in first subplot + ax[0].hist(first) + + #drawing histogram in second subplot + ax[1].hist(second) + + plt.show() + + + +plot_inning_runs_histogram() + + From 456f628fb879d0586b19a404c4ad2bc7a3d058ea Mon Sep 17 00:00:00 2001 From: tracedence Date: Wed, 26 Sep 2018 04:57:02 +0000 Subject: [PATCH 5/5] Done --- q04_plot_runs_by_balls/build.py | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/q04_plot_runs_by_balls/build.py b/q04_plot_runs_by_balls/build.py index ce53182..def5e07 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,24 @@ # Solution +def plot_runs_by_runs(): + # number of balls played by players + no_of_balls = ipl_df.groupby('batsman').count()['delivery'] + # total runs made by players + runs = ipl_df.groupby('batsman', sort = True).sum()['runs'] + #creating figure for plotting data + fig = plt.figure() + #using scatter function to show relationship between no of balls and runs + plt.scatter(no_of_balls, runs) + + plt.xlabel('balls playesd') + plt.ylabel('runs scored') + + plt.show() +plot_runs_by_runs() + + + + + +