Skip to content

Commit Live PR #181

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 4 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
18 changes: 16 additions & 2 deletions q01_plot_deliveries_by_team/build.py
Original file line number Diff line number Diff line change
@@ -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()



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

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

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