diff --git a/q01_plot_deliveries_by_team/build.py b/q01_plot_deliveries_by_team/build.py index d1dab11..974b5b6 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,24 @@ # Solution +def plot_deliveries_by_team(): + + #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'] + + # plot bar graph + plt.bar(data.index, data.values) + + # rotate ticks of x axis by 30 + plt.xticks(rotation = 30) + 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..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() + + + 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() + + 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() + + + + + +