Player Performance Analysis(Cricket)

# importing essential libraries and packages
import pandas as pd
import numpy as np
import datetime
import matplotlib.pyplot as plt
import seaborn as sns
# Reading the data
data= pd.read_csv('Untitled spreadsheet - Sheet1.csv')
%pylab inline
import matplotlib.pyplot as plt
import matplotlib.image as mpimg
img = mpimg.imread('Hitman_apr5_nL4b0Eg_mkWj5hb_1_qs4QpIy_FAC1mG5_qchZ22J_BkVTAV020210916172806.jpg')
imgplot = plt.imshow(img)
plt.show()
not_outs = data['100s'].sum() # number of not outs in career
print('Not outs:', not_outs)
Not outs: 28
p=data.iloc[12:24]
p=d1
d1= data.rename(columns={"Match type": "Opposition"})
d1

Creating the data frame to show the runs scored vs different opposition by Rohit Sharma

from pandas import DataFrameData =  ['Runs','Match type']df = DataFrame(p,columns=['Runs','Match type'])print (df)Output     Runs       Match type
12 1 vs Afghanistan
13 318 vs Australia
14 452 vs Bangladesh
15 317 vs England
16 149 vs Ireland
17 338 vs New Zealand
18 70 vs Pakistan
19 362 vs South Africa
20 289 vs Sri Lanka
21 39 vs U.A.E.
22 519 vs West Indies
23 10 vs Zimbabwe

Centuries against different teams

p[['Match type','100s']]
N100s = pd.DataFrame(p.groupby('Match type')['100s'].sum())
N100s.plot(kind='bar', title='100s against different oppositions', figsize=(8, 5))
plt.ylim(0,3);

Number of Not out against different opposition

Not_out = pd.DataFrame(p.groupby('Match type')['NO'].sum())
Not_out.plot(kind='bar', title='Number of Not out against different oppositions', figsize=(8, 5))
plt.ylim(0,5);

Number of matches played against different oppositions

Different_opposition = pd.DataFrame(p.groupby('Match type')['Mat'].sum())
Different_opposition.plot(kind='bar', title='Number of match played against different oppositions', figsize=(8, 5))
plt.ylim(0,30);
d1[['Opposition','Span','Mat','Inns','Runs','HS','Avg','SR']]c=d1.iloc[0:7]

Runs scored in the ICC tournaments

#splitting required rows
c=d1.iloc[0:7]
c
#Dropping the rows
df = c.drop([3,4])
df
d=df.Mat.sum()d1=df.Runs.sum()k= d1/dprint('Number of Matches Played in official Tournaments:',d)
print('Number of Runs Scores Played:',d1)
print('Average in the tournaments:',k)

Runs scored under the different captaincy

q1=data.iloc[24:28]q3=q1.rename(columns={"Match type": "Captaincy"})
q4=q3.drop([25])
# Converting string into Numeric
q4['HS'] = q4['HS'].astype(int)

Highest score in T20 under his Captaincy(118 Runs)

runs_scored_by_opposition = pd.DataFrame(q4.groupby('Captaincy')['HS'].sum())runs_scored_by_opposition.plot(kind='bar', title='Highest score in T20 under his Captaincy', figsize=(8, 5))plt.ylim(0,200);

Runs scored in India and other countries

#splitting the data
l=data.iloc[3:5]

Number 100's scored in India and other countries

away = pd.DataFrame(l.groupby('Match type')['100s'].sum())
away.plot(kind='bar', title='100s scored in home and away against different oppositions', figsize=(8, 5))
plt.ylim(0,10);
import pandas as pd
import plotly.express as px
import plotly.io as pio
grouping = df.groupby('Opposition')['Runs', 'Opposition', 'Inns','NO'].sum().reset_index()
fig = px.line(grouping, y="Runs", x='Opposition',
title="Total runs scored by Rohit Shama in the all ICC Tournaments")
fig.show()

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Sridhar

Sridhar

32 Followers

Data science Enthusiast|Cricketer| Gymmer| Blog Writer