diff --git a/q01_plot_deliveries_by_team/build.py b/q01_plot_deliveries_by_team/build.py index d1dab11..215e93c 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 @@ -5,5 +6,19 @@ ipl_df = pd.read_csv('data/ipl_dataset.csv', index_col=None) +def plot_deliveries_by_team(): + x = ipl_df['batting_team'] + #y = ipl_df.groupby('batting_team')['delivery'].count() + y = ipl_df['delivery'] + print(x.shape,y.shape) + #plt.scatter(x,y) + plt.plot(x,y) + plt.show() + +#plot_deliveries_by_team() + # Solution + + + diff --git a/q02_plot_matches_by_team/build.py b/q02_plot_matches_by_team/build.py index ce53182..53362bf 100644 --- a/q02_plot_matches_by_team/build.py +++ b/q02_plot_matches_by_team/build.py @@ -1,8 +1,20 @@ +# %load q02_plot_matches_by_team/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) - +def plot_matches_by_team(): + x_team = ipl_df['batting_team'] + #y_count = ipl_df.groupby('batting_team')['match_code'].count() + y_count = ipl_df['match_code'] + #print(y_count) + plt.scatter(x_team,y_count) + plt.plot(x_team,y_count) + plt.show() # Solution +plot_matches_by_team() + + + diff --git a/q03_plot_innings_runs_histogram/build.py b/q03_plot_innings_runs_histogram/build.py index ce53182..132ab30 100644 --- a/q03_plot_innings_runs_histogram/build.py +++ b/q03_plot_innings_runs_histogram/build.py @@ -1,8 +1,23 @@ +# %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 plot_innings_runs_histogram(): + #x = ipl_df.where(ipl_df['inning']==1)['runs'] + x1 = ipl_df.where(ipl_df['inning']==1, other = 0)['runs'] + x2 = ipl_df.where(ipl_df['inning']==2, other = 0)['runs'] + #print(x) + plt.figure() + plt.subplot(121) + plt.hist(x1) + plt.subplot(122) + plt.hist(x2) + +plot_innings_runs_histogram() + + diff --git a/q04_plot_runs_by_balls/build.py b/q04_plot_runs_by_balls/build.py index ce53182..e83dd53 100644 --- a/q04_plot_runs_by_balls/build.py +++ b/q04_plot_runs_by_balls/build.py @@ -1,8 +1,25 @@ +# %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() + +