In [3]:
#Explore Data
import pandas as pd
df = pd.read_csv('EPL_20_21.csv')
df.info()
<class 'pandas.core.frame.DataFrame'>
RangeIndex: 532 entries, 0 to 531
Data columns (total 18 columns):
 #   Column                 Non-Null Count  Dtype  
---  ------                 --------------  -----  
 0   Name                   532 non-null    object 
 1   Club                   532 non-null    object 
 2   Nationality            532 non-null    object 
 3   Position               532 non-null    object 
 4   Age                    532 non-null    int64  
 5   Matches                532 non-null    int64  
 6   Starts                 532 non-null    int64  
 7   Mins                   532 non-null    int64  
 8   Goals                  532 non-null    int64  
 9   Assists                532 non-null    int64  
 10  Passes_Attempted       532 non-null    int64  
 11  Perc_Passes_Completed  532 non-null    float64
 12  Penalty_Goals          532 non-null    int64  
 13  Penalty_Attempted      532 non-null    int64  
 14  xG                     532 non-null    float64
 15  xA                     532 non-null    float64
 16  Yellow_Cards           532 non-null    int64  
 17  Red_Cards              532 non-null    int64  
dtypes: float64(3), int64(11), object(4)
memory usage: 74.9+ KB
In [344]:
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()
In [81]:
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()
383
In [345]:
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()
In [340]:
#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()
               Name    xG  Goals               Club Position
110     Jamie Vardy  0.62     15     Leicester City       FW
81    Mohamed Salah  0.61     22       Liverpool FC       FW
162      Harry Kane  0.60     23  Tottenham Hotspur       FW
19   Olivier Giroud  0.58      4            Chelsea       FW
16    Tammy Abraham  0.56      6            Chelsea       FW
46    Sergio Agüero  0.54      4    Manchester City    FW,MF
203      Martinelli  0.53      2            Arsenal       FW
461       Josh Maja  0.53      3             Fulham    FW,MF
92       Diogo Jota  0.53      9       Liverpool FC       FW
205   Eddie Nketiah  0.52      2            Arsenal       FW
In [118]:
#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()
In [17]:
#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()
                      Name    xG  Goals               Club Position
162             Harry Kane  0.60     23  Tottenham Hotspur       FW
81           Mohamed Salah  0.61     22       Liverpool FC       FW
51         Bruno Fernandes  0.45     18  Manchester United       MF
214        Patrick Bamford  0.51     17       Leeds United       FW
161          Son Heung-min  0.30     17  Tottenham Hotspur       FW
237  Dominic Calvert-Lewin  0.48     16            Everton       FW
110            Jamie Vardy  0.62     15     Leicester City       FW
267          Ollie Watkins  0.43     14        Aston Villa       FW
191    Alexandre Lacazette  0.46     13            Arsenal       FW
33          İlkay Gündoğan  0.40     13    Manchester City       MF
In [25]:
#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()
In [343]:
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()
In [191]:
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()
In [120]:
#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()
In [189]:
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()
In [200]:
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()
In [43]:
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()
In [39]:
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()
                  Name              Club Nationality Position  Age  Matches  \
0          Mason Mount           Chelsea         ENG    MF,FW   21       36   
1        Edouard Mendy           Chelsea         SEN       GK   28       31   
2          Timo Werner           Chelsea         GER       FW   24       35   
3         Ben Chilwell           Chelsea         ENG       DF   23       27   
4          Reece James           Chelsea         ENG       DF   20       32   
..                 ...               ...         ...      ...  ...      ...   
527        Lys Mousset  Sheffield United         FRA    FW,MF   24       11   
528     Jack O'Connell  Sheffield United         ENG       DF   26        2   
529      Iliman Ndiaye  Sheffield United         FRA       MF   21        1   
530  Antwoine Hackford  Sheffield United         ENG    DF,FW   16        1   
531        Femi Seriki  Sheffield United         ENG       DF   17        1   

     Starts  Mins  Goals  Assists  Passes_Attempted  Perc_Passes_Completed  \
0        32  2890      6        5              1881                   82.3   
1        31  2745      0        0              1007                   84.6   
2        29  2602      6        8               826                   77.2   
3        27  2286      3        5              1806                   78.6   
4        25  2373      1        2              1987                   85.0   
..      ...   ...    ...      ...               ...                    ...   
527       2   296      0        0                50                   80.0   
528       2   180      0        0                77                   77.9   
529       0    12      0        0                 3                  100.0   
530       0    11      0        0                 1                  100.0   
531       0     1      0        0                 0                   -1.0   

     Penalty_Goals  Penalty_Attempted    xG    xA  Yellow_Cards  Red_Cards  \
0                1                  1  0.21  0.24             2          0   
1                0                  0  0.00  0.00             2          0   
2                0                  0  0.41  0.21             2          0   
3                0                  0  0.10  0.11             3          0   
4                0                  0  0.06  0.12             3          0   
..             ...                ...   ...   ...           ...        ...   
527              0                  0  0.22  0.10             0          0   
528              0                  0  0.00  0.00             0          0   
529              0                  0  0.00  0.00             0          0   
530              0                  0  1.16  0.00             0          0   
531              0                  0  0.00  0.00             0          0   

     Penalty_Accuracy  
0                 1.0  
1                 NaN  
2                 NaN  
3                 NaN  
4                 NaN  
..                ...  
527               NaN  
528               NaN  
529               NaN  
530               NaN  
531               NaN  

[532 rows x 19 columns]
In [58]:
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()
In [79]:
#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()
In [78]:
#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()
In [80]:
#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()
In [370]:
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()
In [367]:
#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()
In [246]:
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()
In [415]:
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()
In [425]:
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()
In [375]:
# Age (Fix the positions from before)
import plotly.express as px
fig = px.histogram(df, x="Age")
fig.show()
In [336]:
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()
In [335]:
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()
In [338]:
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()
In [332]:
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()
In [331]:
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()
In [339]:
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()
In [323]:
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()
In [324]:
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)
In [306]:
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()
In [301]:
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()
In [298]:
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()
In [297]:
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()
In [286]:
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()
In [441]:
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()
In [445]:
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()
In [442]:
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()
In [ ]: