Skip to content

Commit Live PR #161

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions q01_plot_deliveries_by_team/build.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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()





16 changes: 16 additions & 0 deletions q02_plot_matches_by_team/build.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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()



33 changes: 33 additions & 0 deletions q03_plot_innings_runs_histogram/build.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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()


22 changes: 22 additions & 0 deletions q04_plot_runs_by_balls/build.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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()