In [1]:
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
import datetime as dt
import matplotlib.pyplot as plt
import matplotlib.dates as mdates
import seaborn as sns
import plotly.plotly as py
import plotly.graph_objs as go
%matplotlib notebook
In [2]:
IB = pd.read_csv("india-batting.csv")
In [3]:
IB.head(5)
Out[3]:
In [4]:
IB.columns
Out[4]:
In [5]:
year=[]
for i in range(len(IB)):
x = IB['Start Date'][i].split(" ")[-1]
year.append(x)
In [6]:
year= pd.DataFrame(year,columns=["year"])
mr = [IB,year]
In [7]:
df=pd.concat(mr,axis=1)
df.head(5)
Out[7]:
In [8]:
df_16 = df[df["year"]=="2016"]
In [9]:
df_16=df_16.reset_index(drop=True)
df_16.columns
Out[9]:
In [10]:
Runs = np.array(df_16["Runs"])
In [11]:
np.squeeze(np.where(Runs=="DNB"))
Out[11]:
In [12]:
ndf_16=df_16[0:88]
ndf_16.head(5)
Out[12]:
In [13]:
ndf_16.Player.unique()
Out[13]:
In [14]:
playernames = ndf_16.Player.unique()
In [15]:
runs=[]
for i in range(len(ndf_16)):
try:
r = np.int(ndf_16['Runs'][i])
except:
r= np.int(ndf_16.Runs.unique()[0].split("*")[0])
runs.append(r)
modRun = pd.DataFrame(runs,columns=["modRun"])
modDf = pd.concat([ndf_16,modRun],axis=1)
In [16]:
def PlayerMaxRun(playername):
tmpPlayer = modDf[modDf["Player"]==playername]
tmpPlayer = tmpPlayer.reset_index(drop=True)
maxrun = np.max(np.array(tmpPlayer["modRun"]))
totalrun = sum(np.array(tmpPlayer["modRun"]))
return (maxrun,totalrun)
In [17]:
tb1=[]
rnn=[]
for i in playernames:
[mxrn,trn] = PlayerMaxRun(i)
tb1.append([i,mxrn,trn])
rnn.append(mxrn)
In [18]:
tb1
Out[18]:
In [19]:
dfx = pd.DataFrame(tb1,columns=['player_name','max_run','total_run'])
dfx
Out[19]:
In [20]:
import plotly
plotly.tools.set_credentials_file(username='ayon.mi1', api_key='iIBYMNu0RVcR1GmQSeD0')
In [21]:
data = [go.Bar(
x=np.array(dfx['player_name']),
y=np.array(dfx['max_run'])
)]
layout = go.Layout(
title='Maximun_Score per player',
xaxis=dict(
title='Players_name',
titlefont=dict(
family='Courier New, monospace',
size=18,
color='#7f7f7f'
)
),
yaxis=dict(
title='Max_Run',
titlefont=dict(
family='Courier New, monospace',
size=18,
color='#7f7f7f'
)
)
)
fig = go.Figure(data=data, layout=layout)
py.iplot(fig, filename='basic-bar')
Out[21]:
In [22]:
from IPython.display import Image
Image(filename='f1.png')
Out[22]:
In [24]:
data = [go.Bar(
x=np.array(dfx['player_name']),
y=np.array(dfx['total_run'])
)]
layout = go.Layout(
title='Total_Run per player',
xaxis=dict(
title='Players_name',
titlefont=dict(
family='Courier New, monospace',
size=18,
color='#7f7f7f'
)
),
yaxis=dict(
title='Total_run',
titlefont=dict(
family='Courier New, monospace',
size=18,
color='#7f7f7f'
)
)
)
fig = go.Figure(data=data, layout=layout)
py.iplot(fig, filename='basic-bar')
Out[24]:
In [25]:
from IPython.display import Image
Image(filename='f2.png')
Out[25]:
In [ ]: