-
Notifications
You must be signed in to change notification settings - Fork 194
Expand file tree
/
Copy pathbuild.py
More file actions
34 lines (27 loc) · 921 Bytes
/
build.py
File metadata and controls
34 lines (27 loc) · 921 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#%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
plt.switch_backend('agg')
ipl_df = pd.read_csv('data/ipl_dataset.csv', index_col=None)
# 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()