-
Notifications
You must be signed in to change notification settings - Fork 194
Expand file tree
/
Copy pathbuild.py
More file actions
25 lines (20 loc) · 857 Bytes
/
build.py
File metadata and controls
25 lines (20 loc) · 857 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# %load q04_plot_runs_by_balls/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 plot_runs_by_balls():
ball_count = ipl_df[['match_code','batsman','delivery']].groupby(['match_code','batsman'])['delivery'].count()
runs = ipl_df[['match_code','batsman','runs']].groupby(['match_code','batsman'])['runs'].sum()
ball_count = pd.DataFrame(ball_count, columns = ['match_code','batsman','delivery'])
runs = pd.DataFrame(runs, columns = ['match_code','batsman','runs'])
#print(runs)
merged = pd.merge(ball_count,runs, left_on= 'match_code', right_on= 'match_code')
x = merged['delivery']
y = merged['runs']
plt.figure()
plt.subplot(111)
plt.scatter(x,y)
plot_runs_by_balls()