#Explore Data
import pandas as pd
df = pd.read_csv('EPL_20_21.csv')
df.info()
import plotly.express as px
df = pd.read_csv('EPL_20_21.csv')
# fig = px.scatter(df, x="sepal_width", y="sepal_length", color="species",
# size='petal_length', hover_data=['petal_width'])
dfxg = df
dfxg['xG_Total'] = dfxg['xG']*dfxg['Mins']/90
fig = px.scatter(dfxg, x="xG_Total", y="Goals",hover_data=['Name'],color="Club",trendline="ols")
#
fig.update_layout(
title={
'text': "xG to Goal Graph with Team Regression",
'y':0.95,
'x':0.5,
'xanchor': 'center',
'yanchor': 'top'},
font_family="Calibri",
title_font_family="Times New Roman",
updatemenus=[go.layout.Updatemenu(
active=0,
buttons=list(
[dict(label = 'With Line',
method = 'update',
args = [{'visible': [True, True]},
{'title': 'Total xG to Assists Graph with Team Regression',
'showlegend':True}]),
dict(label = 'Without Line',
method = 'update',
args = [{'visible': [True, False]}, # the index of True aligns with the indices of plot traces
{'title': 'Total xG to Goals Graph',
'showlegend':True}])
])
)
]
)
fig.show()
import plotly.express as px
import pandas as pd
df = pd.read_csv('EPL_20_21.csv')
df2 = df[df['Matches']>10]
print(len(df2))
fig = px.scatter(df2, x="xG", y="Goals",trendline="ols",hover_data=['Name','Club'])
#
fig.update_layout(
title={
'text': "xG per90 to Goal Graph",
'y':0.95,
'x':0.5,
'xanchor': 'center',
'yanchor': 'top'},
font_family="Calibri",
title_font_family="Times New Roman"
)
fig.show()
df = pd.read_csv('EPL_20_21.csv')
# import plotly.express as px
import plotly.graph_objects as go
dfg = df[['Name','Club','Position','Goals','xG']]
# fig = px.scatter(dfa, x="xA", y="Assists",hover_data=['Name','Club'],trendline="ols")
dfmu = dfg[dfg['Club']=='Manchester United']
dfmu = dfmu.sort_values(by=['xG'],ascending=True)
dfmc= dfg[dfg['Club']=='Manchester City']
dfmc = dfmc.sort_values(by=['xG'],ascending=True)
dfl= dfg[dfg['Club']=='Liverpool FC']
dfl = dfl.sort_values(by=['xG'],ascending=True)
dfc= dfg[dfg['Club']=='Chelsea']
dfc = dfc.sort_values(by=['xG'],ascending=True)
plot = go.Figure(data=[go.Scatter(
name='Manchester United',
x=dfmu.xG,
y=dfmu.Goals,
mode = 'markers',
hovertext = dfmu.Name
),
go.Scatter(
name='Manchester City',
x=dfmc.xG,
y=dfmc.Goals,
mode = 'markers',
hovertext = dfmc.Name
),
go.Scatter(
name='Liverpool FC',
x=dfl.xG,
y=dfl.Goals,
mode = 'markers',
hovertext = dfl.Name
),
go.Scatter(
name='Chelsea',
x=dfc.xG,
y=dfc.Goals,
mode = 'markers',
hovertext = dfc.Name
)
])
plot.update_layout(
xaxis_title="xG per 90",
yaxis_title="Total Goals",
title={
'text': "Top 4 xG to Goal Graph",
'y':0.95,
'x':0.5,
'xanchor': 'center',
'yanchor': 'top'},
font_family="Calibri",
title_font_family="Times New Roman",
updatemenus=[
dict(
active=0,
buttons=list([
dict(label="All",
method="update",
args=[{"visible": [True, True, True, True]},
{"title": "Top 4"}]),
dict(label="Manchester United",
method="update",
args=[{"visible": [True, False, False, False]},
{"title": "Manchester United",
}]),
dict(label="Manchester City",
method="update",
args=[{"visible": [False, True, False, False]},
{"title": "Manchester City",
}]),
dict(label="Liverpool FC",
method="update",
args=[{"visible": [False, False, True, False]},
{"title": "Liverpool FC",
}]),
dict(label="Chelsea",
method="update",
args=[{"visible": [False, False, False, True]},
{"title": "Chelsea",
}]),
]),
)
])
plot.show()
#xG for Players that played more than 10 games
df2 = df[df['Matches']>10].sort_values('xG',ascending=False)[['Name','xG','Goals','Club','Position']].head(10)
print(df2)
fig = px.bar(df2, x='Name', y='xG',hover_data=['Club','Position'],color='Position') #,color='Position'
fig.update_layout(
title={
'text': "Top 10 xG per90 Scorers (more than 10 games)",
'y':0.95,
'x':0.5,
'xanchor': 'center',
'yanchor': 'top'},
font_family="Calibri",
title_font_family="Times New Roman",
title_font_color="black",
legend_title_font_color="red",
xaxis_categoryorder = 'total descending'
)
fig.show()
#xG for Players that played more than 10 games
import pandas as pd
df2 = df[df['Matches']>1].sort_values('Goals',ascending=False)[['Name','xG','Goals','Club','Position']]
df2x = df2[df2['Position']=='DF,MF']
df3 = df2[df2['Position']=='DF']
df4 = pd.concat([df2x, df3], ignore_index=True, sort=False)
df4 = df4.sort_values('Goals',ascending=False)[['Name','xG','Goals','Club','Position']]
fig = px.bar(df4[df4['Goals']>0], y='Name', x='Goals',hover_data=['Club','Position','xG'],color='Club') #,color='Position'
fig.update_layout(
title={
'text': "Top Goalscoring Defenders (Zoom for more)",
'y':0.95,
'x':0.5,
'xanchor': 'center',
'yanchor': 'top'},
font_family="Calibri",
title_font_family="Times New Roman",
title_font_color="black",
legend_title_font_color="red",
yaxis_categoryorder = 'total descending'
)
fig.show()
#Num Goals scored for Players that played more than 10 games
df2 = df[df['Matches']>10].sort_values('Goals',ascending=False)[['Name','xG','Goals','Club','Position']].head(10)
print(df2)
fig = px.bar(df2, x='Name', y='Goals',hover_data=['Club'],color='Position') #
# category_orders=dict(group=d)
fig.update_layout(
title={
'text': "Top 10 Goalscorers",
'y':0.95,
'x':0.5,
'xanchor': 'center',
'yanchor': 'top'},
font_family="Calibri",
title_font_family="Times New Roman",
title_font_color="black",
legend_title_font_color="red",
xaxis_categoryorder = 'total descending'
)
fig.update_layout(yaxis_categoryorder = 'total ascending')
fig.show()
#Goals to XG ratio scored for Players that played more than 10 games
df3 = df2
df3['Goals/xG'] = df2['Goals']/df2['xG']
df3 = df3.sort_values('Goals/xG',ascending=False)[['Name','xG','Goals','Goals/xG','Club']].head(10)
fig = px.bar(df3, x='Name', y='Goals/xG',hover_data=['Club','Goals','xG'],color='Club') #,color='Club'
# fig.update_layout(
# title="Most Clinical Goalscorers",
# font=dict(
# family="Courier New, monospace",
# size=18,
# color="RebeccaPurple")
fig.update_layout(
title={
'text': "Most Clinical Goalscorers",
'y':0.95,
'x':0.48,
'xanchor': 'center',
'yanchor': 'top'},
font_family="Calibri",
title_font_family="Times New Roman",
title_font_color="black",
legend_title_font_color="red",
xaxis_categoryorder = 'total descending'
)
fig.show()
dfxa['xA_Total'] = dfxg['xA']*dfxg['Mins']/90
fig = px.scatter(dfxa, x="xA_Total", y="Assists",hover_data=['Name'],color="Club",trendline="ols")
fig.update_layout(
title={
'text': "xA to Assists Graph with Team Regression",
'y':0.95,
'x':0.5,
'xanchor': 'center',
'yanchor': 'top'},
font_family="Calibri",
title_font_family="Times New Roman"
)
fig.update_layout(
updatemenus=[go.layout.Updatemenu(
active=0,
buttons=list(
[dict(label = 'With Line',
method = 'update',
args = [{'visible': [True, True]},
{'title': 'Total xA to Assists Graph with Team Regression',
'showlegend':True}]),
dict(label = 'Without Line',
method = 'update',
args = [{'visible': [True, False]}, # the index of True aligns with the indices of plot traces
{'title': 'xA to Assists Graph',
'showlegend':True}])
])
)
])
#
fig.show()
df = pd.read_csv('EPL_20_21.csv')
import plotly.express as px
import plotly.graph_objects as go
buttons=[]
# for Club in pd.unique(dfa.Club):
# buttons.append(dict(method='update',
# label=Club,
# args = [{'visible': dfa= dfa[dfa['Club']==Club]}]))
dfa = df[df['Matches']>10]
dfa = dfa[['Name','Club','Position','Assists','xA']]
# print(dfa.info)
fig = px.scatter(dfa, x="xA", y="Assists",hover_data=['Name','Club'],trendline="ols")
# region_plot_names = dfa.Club
# fig.update_layout(updatemenus=[{"buttons": buttons, "direction": "down", "active": dfa.index(default_state), "showactive": True, "x": 0.5, "y": 1.15}])
fig.update_layout(
xaxis_title="xA per game",
yaxis_title="Total Assists",
title={
'text': "xA per90 to Assists Graph (For players who played over 10 games)",
'y':0.95,
'x':0.5,
'xanchor': 'center',
'yanchor': 'top'},
font_family="Calibri",
title_font_family="Times New Roman"
)
fig.show()
#xG for Players that played more than 10 games
import pandas as pd
df2 = df[df['Matches']>1].sort_values('Assists',ascending=False)[['Name','xA','Assists','Club','Position']]
df2x = df2[df2['Position']=='DF,MF']
df3 = df2[df2['Position']=='DF']
df3x = df2[df2['Position']=='DF,FW']
df3y = df2[df2['Position']=='DF,MF,FW']
df4 = pd.concat([df2x, df3,df3x,df3y], ignore_index=True, sort=False)
df4 = df4.sort_values('Assists',ascending=False)[['Name','xA','Assists','Club','Position']]
fig = px.bar(df4[df4['Assists']>0], y='Name', x='Assists',hover_data=['Club','Position','xA'],color='Club') #,color='Position'
fig.update_layout(
title={
'text': "Top Assisting Defenders (Zoom for more)",
'y':0.95,
'x':0.5,
'xanchor': 'center',
'yanchor': 'top'},
font_family="Calibri",
title_font_family="Times New Roman",
title_font_color="black",
legend_title_font_color="red",
yaxis_categoryorder = 'total descending'
)
fig.show()
df = pd.read_csv('EPL_20_21.csv')
# import plotly.express as px
import plotly.graph_objects as go
dfa = df[['Name','Club','Position','Assists','xA']]
# fig = px.scatter(dfa, x="xA", y="Assists",hover_data=['Name','Club'],trendline="ols")
dfmu = dfa[dfa['Club']=='Manchester United']
dfmu = dfmu.sort_values(by=['xA'],ascending=True)
dfmc= dfa[dfa['Club']=='Manchester City']
dfmc = dfmc.sort_values(by=['xA'],ascending=True)
dfl= dfa[dfa['Club']=='Liverpool FC']
dfl = dfl.sort_values(by=['xA'],ascending=True)
dfc= dfa[dfa['Club']=='Chelsea']
dfc = dfc.sort_values(by=['xA'],ascending=True)
plot = go.Figure(data=[go.Scatter(
name='Manchester United',
x=dfmu.xA,
y=dfmu.Assists,
mode = 'markers',
hovertext = dfmu.Name
),
go.Scatter(
name='Manchester City',
x=dfmc.xA,
y=dfmc.Assists,
mode = 'markers',
hovertext = dfmc.Name
),
go.Scatter(
name='Liverpool FC',
x=dfl.xA,
y=dfl.Assists,
mode = 'markers',
hovertext = dfl.Name
),
go.Scatter(
name='Chelsea',
x=dfc.xA,
y=dfc.Assists,
mode = 'markers',
hovertext = dfc.Name
)
])
plot.update_layout(
xaxis_title="xA per game",
yaxis_title="Goals",
title={
'text': "Top 4 xA to Goal Graph",
'y':0.95,
'x':0.5,
'xanchor': 'center',
'yanchor': 'top'},
font_family="Calibri",
updatemenus=[
dict(
active=0,
buttons=list([
dict(label="All",
method="update",
args=[{"visible": [True, True, True, True]},
{"title": "Top 4"}]),
dict(label="Manchester United",
method="update",
args=[{"visible": [True, False, False, False]},
{"title": "Manchester United",
}]),
dict(label="Manchester City",
method="update",
args=[{"visible": [False, True, False, False]},
{"title": "Manchester City",
}]),
dict(label="Liverpool FC",
method="update",
args=[{"visible": [False, False, True, False]},
{"title": "Liverpool FC",
}]),
dict(label="Chelsea",
method="update",
args=[{"visible": [False, False, False, True]},
{"title": "Chelsea",
}]),
]),
)
])
plot.show()
dfp = df[df['Penalty_Goals']>0].sort_values('Penalty_Goals',ascending=False)[['Name','Penalty_Attempted','Penalty_Goals','Club','Position']]
fig = px.bar(dfp, x='Name', y='Penalty_Goals',hover_data=['Position'],color='Club') #
# category_orders=dict(group=d)
fig.update_layout(
title={
'text': "All Penalty Goalscorers",
'y':0.95,
'x':0.5,
'xanchor': 'center',
'yanchor': 'top'},
font_family="Calibri",
title_font_family="Times New Roman",
title_font_color="black",
legend_title_font_color="red",
xaxis_categoryorder = 'total descending'
)
fig.update_layout(yaxis_categoryorder = 'total ascending')
fig.show()
dfp = df
dfp['Penalty_Accuracy'] = dfp['Penalty_Goals']/dfp['Penalty_Attempted']
dfp = df[df['Penalty_Attempted']>0].sort_values('Penalty_Attempted',ascending=False)[['Name','Penalty_Attempted','Penalty_Goals','Club','Position','Penalty_Accuracy']]
fig = px.bar(dfp, y='Name', x='Penalty_Accuracy',hover_data=['Position'],color='Penalty_Goals') #
# category_orders=dict(group=d)
fig.update_layout(
title={
'text': "All Penalty Goalscorers",
'y':0.95,
'x':0.5,
'xanchor': 'center',
'yanchor': 'top'},
font_family="Calibri",
title_font_family="Times New Roman",
title_font_color="black",
legend_title_font_color="red",
xaxis_categoryorder = 'total descending'
)
fig.update_layout(yaxis_categoryorder = 'total ascending')
fig.show()
print(df)
fig = px.scatter(df, x="Mins", y="Passes_Attempted",hover_data=['Name','Club'],trendline="ols",color='Perc_Passes_Completed')
fig.update_layout(
title={
'text': "Passes Attempted by All Prem Players",
'y':0.95,
'x':0.5,
'xanchor': 'center',
'yanchor': 'top'},
font_family="Calibri",
title_font_family="Times New Roman",
title_font_color="black",
legend_title_font_color="red",
xaxis_categoryorder = 'total descending'
)
fig.show()
import plotly.graph_objects as go
import numpy as np
dfpc = df
# fig = px.scatter(dfa, x="xA", y="Assists",hover_data=['Name','Club'],trendline="ols")
dffw = dfpc[dfpc['Position']=='FW']
dffw = dffw.sort_values(by=['Mins'],ascending=True)
dfmf = dfpc[dfpc['Position']=='MF']
dfmf = dfmf.sort_values(by=['Mins'],ascending=True)
dfdf= dfpc[dfpc['Position']=='DF']
dfdf = dfdf.sort_values(by=['Mins'],ascending=True)
dfgk= dfpc[dfpc['Position']=='GK']
dfgk = dfgk.sort_values(by=['Mins'],ascending=True)
plot = go.Figure(data=[go.Scatter(
name='1',
x=dffw.Mins,
y=dffw.Passes_Attempted,
showlegend=False,
mode = 'markers',
hovertext = dffw.Name,
marker=dict(
color = dffw.Perc_Passes_Completed,
showscale=True,
colorscale = 'RdBu'
)
),
go.Scatter(
name='2',
x=dfmf.Mins,
showlegend=False,
y=dfmf.Passes_Attempted,
mode = 'markers',
hovertext = dfmf.Name,
marker=dict(
color = dfmf.Perc_Passes_Completed,
showscale=True,
colorscale = 'RdBu'
)
),
go.Scatter(
name='3',
x=dfdf.Mins,
showlegend=False,
y=dfdf.Passes_Attempted,
mode = 'markers',
hovertext = dfdf.Name,
marker=dict(
color = dfdf.Perc_Passes_Completed,
showscale=True,
colorscale = 'RdBu'
)
),
go.Scatter(
name='4',
showlegend=False,
x=dfgk.Mins,
y=dfgk.Passes_Attempted,
mode = 'markers',
hovertext = dfgk.Name,
marker=dict(
color = dfgk.Perc_Passes_Completed,
showscale=True,
colorscale = 'RdBu'
)
)
])
plot.update_layout(
xaxis_title="Total Minutes",
yaxis_title="Passes Attempted",
title={
'text': "Passing of All Players",
'y':0.95,
'x':0.5,
'xanchor': 'center',
'yanchor': 'top'},
font_family="Calibri",
updatemenus=[
dict(
active=0,
buttons=list([
dict(label="Passing of All Players",
method="update",
args=[{"visible": [True, True, True, True]},
{"title": "Top 4"}]),
dict(label="Passing of FWs",
method="update",
args=[{"visible": [True, False, False, False]},
{"title": "Passing of FWs",
}]),
dict(label="Passing of MFs",
method="update",
args=[{"visible": [False, True, False, False]},
{"title": "Passing of MFs",
}]),
dict(label="Passing of DFs",
method="update",
args=[{"visible": [False, False, True, False]},
{"title": "Passing of DFs",
}]),
dict(label="Passing of GKs",
method="update",
args=[{"visible": [False, False, False, True]},
{"title": "Passing of GKs",
}])
]),
)
])
plot.show()
#Num Goals scored for Players that played more than 10 games
df2 = df[df['Passes_Attempted']>500].sort_values('Goals',ascending=False)[['Name','Passes_Attempted','Perc_Passes_Completed','Club','Position']].head(20)
fig = px.bar(df2, x='Name', y='Perc_Passes_Completed',hover_data=['Position'],color='Club') #
# category_orders=dict(group=d)
fig.update_layout(
title={
'text': "Top 20 Best Passers",
'y':0.95,
'x':0.5,
'xanchor': 'center',
'yanchor': 'top'},
font_family="Calibri",
title_font_family="Times New Roman",
title_font_color="black",
legend_title_font_color="red",
xaxis_categoryorder = 'total descending'
)
fig.update_layout(yaxis_categoryorder = 'total ascending')
fig.show()
#Num Goals scored for Players that played more than 10 games
df2 = df[df['Passes_Attempted']>500].sort_values('Goals',ascending=False)[['Name','Passes_Attempted','Perc_Passes_Completed','Club','Position']].head(20)
fig = px.bar(df2, x='Name', y='Passes_Attempted',hover_data=['Position'],color='Club') #
# category_orders=dict(group=d)
fig.update_layout(
title={
'text': "Top 20 Volume Passers",
'y':0.95,
'x':0.5,
'xanchor': 'center',
'yanchor': 'top'},
font_family="Calibri",
title_font_family="Times New Roman",
title_font_color="black",
legend_title_font_color="red",
xaxis_categoryorder = 'total descending'
)
fig.update_layout(yaxis_categoryorder = 'total ascending')
fig.show()
#Num Goals scored for Players that played more than 10 games
dfd = df
dfd['Foul_Rating'] = df['Yellow_Cards']*1 + df['Red_Cards']*2
dfd = dfd[dfd['Foul_Rating']>0].sort_values('Foul_Rating',ascending=False).head(20)
fig = px.bar(dfd, x='Name', y='Foul_Rating',hover_data=['Position','Yellow_Cards','Red_Cards'],color='Club') #
# category_orders=dict(group=d)
fig.update_layout(
title={
'text': "Top 20 Dirtiest Players",
'y':0.95,
'x':0.5,
'xanchor': 'center',
'yanchor': 'top'},
font_family="Calibri",
title_font_family="Times New Roman",
title_font_color="black",
legend_title_font_color="red",
xaxis_categoryorder = 'total descending'
)
fig.update_layout(yaxis_categoryorder = 'total ascending')
fig.show()
import plotly.graph_objects as go
import numpy as np
dfpc = df
dfpc2 = dfpc.sort_values(by=['Mins'],ascending=False).head(20)
dffw = dfpc[dfpc['Position']=='FW']
dffw = dffw.sort_values(by=['Mins'],ascending=False).head(20)
dfmf = dfpc[dfpc['Position']=='MF']
dfmf = dfmf.sort_values(by=['Mins'],ascending=False).head(20)
dfdf= dfpc[dfpc['Position']=='DF']
dfdf = dfdf.sort_values(by=['Mins'],ascending=False).head(20)
dfgk= dfpc[dfpc['Position']=='GK']
dfgk = dfgk.sort_values(by=['Mins'],ascending=False).head(20)
colors = [
'#1f77b4', # muted blue
'#ff7f0e', # safety orange
'#2ca02c', # cooked asparagus green
'#d62728', # brick red
'#9467bd', # muted purple
'#8c564b', # chestnut brown
'#e377c2', # raspberry yogurt pink
'#7f7f7f', # middle gray
'#bcbd22', # curry yellow-green
'#17becf' # blue-teal
]
plot = go.Figure(data=[
go.Bar(
name='',
x=dfpc2.Name,
y=dfpc2.Mins,
hovertext = dfpc2.Club,
visible=True,
marker_color = colors[2]
),
go.Bar(
name='FW',
x=dffw.Name,
y=dffw.Mins,
hovertext = dffw.Club,
visible=False,
marker_color = colors[8]
),
go.Bar(
name='MF',
x=dfmf.Name,
y=dfmf.Mins,
hovertext = dfmf.Club,
visible=False,
marker_color = colors[5]
),
go.Bar(
name='DF',
x=dfdf.Name,
y=dfdf.Mins,
hovertext = dfdf.Club,
visible=False,
marker_color = colors[0]
),
go.Bar(
name='GK',
x=dfgk.Name,
y=dfgk.Mins,
hovertext = dfgk.Club,
visible=False,
marker_color = colors[7]
)
])
plot.update_layout(
xaxis_title="Name",
yaxis_title="Total Mins Played",
title={
# 'text': "Passing of l Players",
'y':0.95,
'x':0.5,
'xanchor': 'center',
'yanchor': 'top'},
font_family="Calibri",
updatemenus=[
go.layout.Updatemenu(
type = "buttons", direction="down",
y=0.7,
x=-0.2,
buttons = list(
[
dict(label="Top Mins of All Players",
method="update",
args=[{"visible": [True, False, False, False, False]},
{"title": "Top Mins Played of All Players",
}]),
dict(label="Top Mins Played of FWs",
method="update",
args=[{"visible": [False, True, False, False, False]},
{"title": "Top Mins Played of FWs",
}]),
dict(label="Top Mins Played of MFs",
method="update",
args=[{"visible": [False, False, True, False, False]},
{"title": "Top Mins Played of MFs",
}]),
dict(label="Top Mins Played of DFs",
method="update",
args=[{"visible": [False, False, False, True, False]},
{"title": "Top Mins Played of DFs",
}]),
dict(label="Top Mins Played of GKs",
method="update",
args=[{"visible": [False, False, False, False, True]},
{"title": "Top Mins Played of GKs",
}])
])
)])
# Update plot sizing
plot.update_layout(
# marker=dict(color=dfpc2.Club),
# width=800,
# height=500,
autosize=True,
margin=dict(t=100, b=100, l=100, r=100),
showlegend=False
)
plot.show()
#Super Sub
dfd = df
dfd['Subbed_On'] = df['Matches']*1 - df['Starts']
dfd = dfd[dfd['Subbed_On']>0].sort_values('Subbed_On',ascending=False).head(20)
fig = px.bar(dfd, x='Name', y='Subbed_On',hover_data=['Position','Starts','Matches','Mins'],color='Club') #
# category_orders=dict(group=d)
fig.update_layout(
title={
'text': "Top 20 Most Subbed On Players",
'y':0.95,
'x':0.45,
'xanchor': 'center',
'yanchor': 'top'},
font_family="Calibri",
title_font_family="Times New Roman",
title_font_color="black",
legend_title_font_color="red",
xaxis_categoryorder = 'total descending'
)
fig.update_layout(yaxis_categoryorder = 'total ascending')
fig.show()
fig = px.scatter(df, x="Mins", y="Matches",hover_data=['Name','Club'],trendline="ols",color='Starts')
fig.update_layout(
title={
'text': "Games Played by All Prem Players",
'y':0.95,
'x':0.5,
'xanchor': 'center',
'yanchor': 'top'},
font_family="Calibri",
title_font_family="Times New Roman",
title_font_color="black",
legend_title_font_color="red",
xaxis_categoryorder = 'total descending',xaxis_title="Total Mins Played",
yaxis_title="Total Matches Started",
)
fig.show()
x = pd.DataFrame(columns = ['Nationality', 'Count'])
# print(x)
for i in df.Nationality.unique():
count = len(df[df['Nationality']==i])
# print(count.info())
# print(i,count)
new_row = {'Nationality': i, 'Count':count}
x = x.append(new_row, ignore_index=True)
x.sort_values(by=['Count'], ascending=True)
num = x.sum().Count
x = x[x['Count']>5]
x = x.append({'Nationality': "OTHER", 'Count':num-x.sum().Count},ignore_index=True)
# print(x)
fig = go.Figure(data=[go.Pie(labels=x.Nationality, values=x.Count, textinfo='label+percent',
insidetextorientation='radial'
)])
fig.update_layout(
title={
'text': "Nationalities of the Premier League",
'y':0.95,
'x':0.5,
'xanchor': 'center',
'yanchor': 'top'},
font_family="Calibri",
title_font_family="Times New Roman"
)
fig.show()
x = pd.DataFrame(columns = ['Club', 'Count'])
for i in df.Club.unique():
eng = df[df['Club']==i]
eng = eng[eng['Nationality']=="ENG"]
count = len(eng)
# print(count.info())
# print(i,count)
new_row = {'Club': i, 'Count':count}
x = x.append(new_row, ignore_index=True)
x.sort_values(by=['Count'], ascending=True)
# print(x)
fig = go.Figure(data=[go.Pie(labels=x.Club, values=x.Count, textinfo='percent',
insidetextorientation='radial'
)])
fig.update_layout(
title={
'text': "English Players in the Premier League",
'y':0.95,
'x':0.5,
'xanchor': 'center',
'yanchor': 'top'},
font_family="Calibri",
title_font_family="Times New Roman"
)
fig.update_traces(textposition='inside')
fig.update_layout(uniformtext_minsize=12, uniformtext_mode='hide')
fig.show()
# Age (Fix the positions from before)
import plotly.express as px
fig = px.histogram(df, x="Age")
fig.show()
dfg = df.sort_values(by=['Goals'], ascending=True)
fig = px.bar(dfg, x="Club", y="Goals",hover_data=['Name','Position'], color="Name", title="Season Total Goals")
fig.update_layout(xaxis_categoryorder = 'total descending',showlegend=False)
fig.show()
dfxg = df.sort_values(by=['xG'], ascending=True)
fig = px.bar(dfxg, x="Club", y="xG", hover_data=['Name','Position'],color="Name", title="xG per90")
fig.update_layout(xaxis_categoryorder = 'total descending',showlegend=False)
fig.show()
dfxg = df
dfxg['xG_Total'] = dfxg['xG']*dfxg['Mins']/90
dfxg = dfxg.sort_values(by=['xG_Total'], ascending=True)
fig = px.bar(dfxg, x="Club", y="xG_Total", hover_data=['Name','Position'],color="Name", title="Season Total xG")
fig.update_layout(xaxis_categoryorder = 'total descending',showlegend=False)
fig.show()
dfa = df.sort_values(by=['Assists'], ascending=True)
fig = px.bar(dfa, x="Club", y="Assists", color="Name", hover_data=['Name','Position'],title="Season Total Assists")
fig.update_layout(xaxis_categoryorder = 'total descending',showlegend=False)
fig.show()
dfxa = df.sort_values(by=['xA'], ascending=True)
fig = px.bar(dfxa, x="Club", y="xA", color="Name", hover_data=['Name','Position'], title="xA per 90")
fig.update_layout(xaxis_categoryorder = 'total descending',showlegend=False)
fig.show()
dfxg = df
dfxa['xA_Total'] = dfxa['xA']*dfxg['Mins']/90
dfxa = dfxa.sort_values(by=['xA_Total'], ascending=True)
fig = px.bar(dfxa, x="Club", y="xA_Total", hover_data=['Name','Position'],color="Name", title="Season Total xA")
fig.update_layout(xaxis_categoryorder = 'total descending',showlegend=False)
fig.show()
dfpa = df.sort_values(by=['Passes_Attempted'], ascending=True)
fig = px.bar(dfpa, x="Club", y="Passes_Attempted", color="Name", title="Passes Attempted")
fig.update_layout(xaxis_categoryorder = 'total descending',showlegend=False)
fig.show()
dfpc = df
dfpc['Passes_Completed'] = dfpc['Passes_Attempted']*dfpc['Perc_Passes_Completed']/100
dfpc = dfpc.sort_values(by=['Passes_Completed'], ascending=True)
fig = px.bar(dfpc, x="Club", y="Passes_Completed", color="Name", hover_data=['Name','Position'], title="Passes Completed")
fig.update_layout(xaxis_categoryorder = 'total descending',showlegend=False)
penalty = df.sort_values(by=['Penalty_Goals'])
fig = px.bar(penalty, x="Club", y="Penalty_Goals", color="Name", hover_data=['Name','Position'],title="Penalty Goals")
fig.update_layout(xaxis_categoryorder = 'total descending',showlegend=False)
fig.show()
yellow = df.sort_values(by=['Yellow_Cards'])
fig = px.bar(yellow, x="Club", y="Yellow_Cards", color="Name", hover_data=['Name','Position'], title="Yellow Cards")
fig.update_layout(xaxis_categoryorder = 'total descending',yaxis_categoryorder = 'total ascending',showlegend=False)
fig.show()
fig = px.bar(df, x="Club", y="Red_Cards", color="Name", hover_data=['Name','Position'], title="Red Cards")
fig.update_layout(xaxis_categoryorder = 'total descending',showlegend=False)
fig.show()
nation = df.sort_values(by=['Club','Nationality'])
fig = px.bar(nation, x="Club", y="Nationality", color="Nationality", hover_data=['Name','Position'], title="Nationality")
fig.update_layout(xaxis_categoryorder = 'total descending')
fig.show()
order = df.sort_values(by=['Starts'])
fig = px.bar(order, x="Starts", y="Club", color="Age", hover_data=['Name','Position'], title="Starts for All Clubs")
fig.update_layout(yaxis_categoryorder = 'total descending',showlegend=False)
fig.show()
fig = px.box(df, x="Club", y="Age",hover_data=['Name'], color="Club",points="all",width=1000)
fig.update_layout(
title={
'text': "Age Box Plot for All Teams",
'y':0.95,
'x':0.45,
'xanchor': 'center',
'yanchor': 'top'},
font_family="Calibri",
title_font_family="Times New Roman"
)
fig.show()
dfffff= df[df['Starts']>10]
fig = px.box(dfffff, x="Club", y="Passes_Attempted",hover_data=['Name'], color="Club",points="all",width=1000)
fig.update_layout(
title={
'text': "Passes Attempted Plot for All Teams (Starts>10)",
'y':0.95,
'x':0.45,
'xanchor': 'center',
'yanchor': 'top'},
font_family="Calibri",
title_font_family="Times New Roman"
)
fig.show()
dfffff= df[df['Mins']>100]
fig = px.box(dfffff, x="Club", y="Perc_Passes_Completed",hover_data=['Name'], color="Club",points="all",width=1000)
fig.update_layout(
title={
'text': "Percent Passes Completed Plot for All Teams (Mins>100)",
'y':0.95,
'x':0.45,
'xanchor': 'center',
'yanchor': 'top'},
font_family="Calibri",
title_font_family="Times New Roman"
)
fig.show()