diff --git a/q01_plot_deliveries_by_team/build.py b/q01_plot_deliveries_by_team/build.py index d1dab11..fbc879c 100644 --- a/q01_plot_deliveries_by_team/build.py +++ b/q01_plot_deliveries_by_team/build.py @@ -1,9 +1,23 @@ +#%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') +from matplotlib import pyplot as plt + +ipl_df=pd.read_csv('./data/ipl_dataset.csv') + +# gr=ipl_df.groupby('batting_team').delivery.agg('count') + +# plt.bar(gr.index,gr,title='Bar graph of \n Batting team vs count of deliveries ') +# plt.show() +def plot_deliveries_by_team(): + ipl_df.groupby('batting_team').delivery.agg('count').plot(kind='bar',title='Batting team vs count of deliveries ') + plt.xlabel=('batsman') + plt.ylabel=('runs') + plt.show() + +plot_deliveries_by_team() + -ipl_df = pd.read_csv('data/ipl_dataset.csv', index_col=None) -# Solution diff --git a/q02_plot_matches_by_team/build.py b/q02_plot_matches_by_team/build.py index ce53182..0bd6c7e 100644 --- a/q02_plot_matches_by_team/build.py +++ b/q02_plot_matches_by_team/build.py @@ -1,8 +1,23 @@ +#%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) + +from matplotlib import pyplot as plt + +ifl_df=pd.read_csv('./data/ipl_dataset.csv') + +def plot_matches_by_team(): + gr=ifl_df.groupby('batting_team')['match_code'].nunique() + gr.plot(kind='bar',title=' total number of matches played by each team') + + plt.xlabel('batsman') + plt.ylabel('matches played') + + plt.show() + +plot_matches_by_team() + + -# Solution diff --git a/q03_plot_innings_runs_histogram/build.py b/q03_plot_innings_runs_histogram/build.py index ce53182..013eae8 100644 --- a/q03_plot_innings_runs_histogram/build.py +++ b/q03_plot_innings_runs_histogram/build.py @@ -1,8 +1,22 @@ -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) +import pandas as pd +from matplotlib import pyplot as plt + +ifl_df=pd.read_csv('./data/ipl_dataset.csv') + +def plot_innings_runs_histogram(): + + gr=ifl_df.groupby(['match_code','inning'])['runs'].sum() +#gr[1::2] + + fig = plt.figure() + ax = fig.add_subplot(121) + gr[1::2].plot(kind='hist',title=' total number of runs inning 1') + ax = fig.add_subplot(122) + gr[2::2].plot(kind='hist',title=' total number of runs inning 2') + + plt.show() + +plot_innings_runs_histogram() -# Solution diff --git a/q04_plot_runs_by_balls/build.py b/q04_plot_runs_by_balls/build.py index ce53182..f539140 100644 --- a/q04_plot_runs_by_balls/build.py +++ b/q04_plot_runs_by_balls/build.py @@ -1,8 +1,29 @@ +#%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) +from matplotlib import pyplot as plt + +ifl_df=pd.read_csv('./data/ipl_dataset.csv') +# ifl_df.columns +# runs,delivery,batsman + +def plot_runs_by_balls(): + + gr=ifl_df.groupby('batsman') + balls=pd.DataFrame(gr['delivery'].count()) + runs=pd.DataFrame(gr['runs'].sum()) + + A=balls.merge(runs, left_index=True,right_index=True, how='inner') + + plt.scatter(A.runs,A.delivery) + plt.xlabel=('runs') + plt.ylabel=('deliveries') + + plt.show() + +# runs + +# plt.scatter(ifl_df[) -# Solution