0% found this document useful (0 votes)
8 views40 pages

DWM Mini Project: Football Data Analysis

This document imports various libraries and reads in data from an SQLite database into Pandas DataFrames. It then performs data cleaning steps like merging datasets and dropping unnecessary columns. Visualizations are created showing the geographic locations of matches played in different countries and leagues.

Uploaded by

Edu Free
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views40 pages

DWM Mini Project: Football Data Analysis

This document imports various libraries and reads in data from an SQLite database into Pandas DataFrames. It then performs data cleaning steps like merging datasets and dropping unnecessary columns. Visualizations are created showing the geographic locations of matches played in different countries and leagues.

Uploaded by

Edu Free
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

4/19/2019 DWM Mini Project

In [ ]: #Import libraries
import numpy as np
import pandas as pd
import sqlite3
from datetime import timedelta
import warnings
[Link]("ignore")
import [Link] as plt
import seaborn as sns
%matplotlib inline
import [Link] as py
py.init_notebook_mode(connected=True)
import plotly.graph_objs as go
import [Link] as tls
import mpl_toolkits
from mpl_toolkits.basemap import Basemap
import folium
import [Link]
from matplotlib import animation,rc
import io
import base64
import itertools
from subprocess import check_output

In [ ]: with [Link]('[Link]') as con:


countries = pd.read_sql_query("SELECT * from Country", con)
matches = pd.read_sql_query("SELECT * from Match", con)
leagues = pd.read_sql_query("SELECT * from League", con)
teams = pd.read_sql_query("SELECT * from Team", con)
player = pd.read_sql_query("SELECT * from Player",con)
player_attributes = pd.read_sql_query("SELECT * from Player_Attributes",con)
sequence = pd.read_sql_query("SELECT * from sqlite_sequence",con)
team_attributes = pd.read_sql_query("SELECT * from Team_Attributes",con)

In [36]: lat_long = pd.read_excel("[Link]",sheetname="Sheet1")

In [ ]: [Link]()
[Link]()
[Link]()
[Link]()
[Link]()
player_attributes.head()
[Link]()
team_attributes.head()

In [ ]: #Merge country and leauge data


countries_leagues = [Link](leagues,left_on="id",right_on="id",how="outer
countries_leagues = countries_leagues.drop("id",axis = 1)
countries_leagues = countries_leagues.rename(columns={'name_x':"country", 'name_y

localhost:8888/notebooks/DWM Mini [Link] 1/40


4/19/2019 DWM Mini Project

In [29]: [Link]()

Out[29]:
id country_id league_id season stage date match_api_id home_team_api_id away_te

2008-
0 1 1 1 2008/2009 1 08-17 492473 9987
00:00:00

2008-
1 2 1 1 2008/2009 1 08-16 492474 10000
00:00:00

2008-
2 3 1 1 2008/2009 1 08-16 492475 9984
00:00:00

2008-
3 4 1 1 2008/2009 1 08-17 492476 9991
00:00:00

2008-
4 5 1 1 2008/2009 1 08-16 492477 7947
00:00:00

5 rows × 115 columns

In [30]: #subsetting data with necessary columns


matches_new = matches[['id', 'country_id', 'league_id', 'season', 'stage', 'date
'match_api_id', 'home_team_api_id', 'away_team_api_id',
'home_team_goal', 'away_team_goal']]

matches_new = matches_new.drop("id",axis=1)

In [31]: #merge leauge data with match data


data = matches_new.merge(countries_leagues,left_on="country_id",right_on="country
#chech null values
[Link]().sum()

Out[31]: country_id 0
league_id 0
season 0
stage 0
date 0
match_api_id 0
home_team_api_id 0
away_team_api_id 0
home_team_goal 0
away_team_goal 0
country 0
league 0
dtype: int64

localhost:8888/notebooks/DWM Mini [Link] 2/40


4/19/2019 DWM Mini Project

In [32]: #Unique values in data


[Link]()

Out[32]: country_id 11
league_id 11
season 8
stage 38
date 1694
match_api_id 25979
home_team_api_id 299
away_team_api_id 299
home_team_goal 11
away_team_goal 10
country 11
league 11
dtype: int64

localhost:8888/notebooks/DWM Mini [Link] 3/40


4/19/2019 DWM Mini Project

In [37]: #getting lat lon info


country_info = countries_leagues.merge(lat_long,left_on="country",right_on="name
country_info = country_info.drop(["country_id","country_y","name"],axis = 1)

m3 = Basemap(projection='ortho', resolution=None, lat_0=50, lon_0=10,urcrnrlat=80

[Link](figsize=(12,12))

country = list(country_info["country_x"].unique())
c = sns.color_palette("Set1",11)
label = country

def function(country,c,label):
lat = list(country_info[country_info["country_x"] == country].latitude)
lon = list(country_info[country_info["country_x"] == country].longitude)
x,y = m3(lon,lat)
[Link](x,y,"go",markersize=15,color=j,alpha=.8,label=i)

for i,j in zip(country,c):


function(i,j,i)

[Link](scale=0.5)
[Link](loc="center right",frameon=True,prop={"size":15}).get_frame().set_face
[Link]("MATCHES PLAYED IN COUNTRIES")
[Link]()

Clipping input data to the valid range for imshow with RGB data ([0..1] for flo
ats or [0..255] for integers).

localhost:8888/notebooks/DWM Mini [Link] 4/40


4/19/2019 DWM Mini Project

localhost:8888/notebooks/DWM Mini [Link] 5/40


4/19/2019 DWM Mini Project

In [38]: #westlimit=-23.8; southlimit=25.8; eastlimit=60.6; northlimit=64.9


m =Basemap(projection="merc",llcrnrlat=35,urcrnrlat=60,llcrnrlon=-12,urcrnrlon=25

[Link](figsize=(15,10))

[Link](fill_color="skyblue",color="k",linewidth=2)
[Link](linewidth=2)
[Link](linewidth=2,color="grey")
[Link](color="gold",alpha=1,lake_color="b")

leag = list(country_info["league"].unique())
c = sns.color_palette("Set1",11)
lat = list(country_info[country_info["league"] == leag].latitude)
lon = list(country_info[country_info["league"] == leag].longitude)
x,y = m(lon,lat)

def function(leag,c):
lat = list(country_info[country_info["league"] == leag].latitude)
lon = list(country_info[country_info["league"] == leag].longitude)
x,y = m(lon,lat)
[Link](x,y,"go",markersize=40,color=j,alpha=.8,linewidth=20)

for i,j in zip(leag,c):


function(i,j)

for i,j,k in itertools.zip_longest(x,y,country_info["league"]):


[Link](i,j,k,fontsize =10,color="k",horizontalalignment='center',verticalal
[Link]("LEAGUES IN DIFFFERT COUNTRIES")
[Link]()

localhost:8888/notebooks/DWM Mini [Link] 6/40


4/19/2019 DWM Mini Project

localhost:8888/notebooks/DWM Mini [Link] 7/40


4/19/2019 DWM Mini Project

In [39]: [Link](figsize=(8,8))
ax = [Link](y = data["league"],
order=data["league"].value_counts().index,
linewidth = 1,
edgecolor = "k"*data["league"].nunique()
)
for i,j in enumerate(data["league"].value_counts().values):
[Link](.7,i,j,weight = "bold")
[Link]("Matches by league")
[Link]()

localhost:8888/notebooks/DWM Mini [Link] 8/40


4/19/2019 DWM Mini Project

In [40]: [Link]("league").agg({"home_team_goal":"sum","away_team_goal":"sum"}).plot

[Link]("Home and away goals by league")


[Link](loc = "best" , prop = {"size" : 14})
[Link]("total goals")
[Link]()

In [41]: #converting to date format


data["date"] = pd.to_datetime(data["date"],format="%Y-%m-%d")
#extracting year
data["year"] = [Link](data["date"]).year

localhost:8888/notebooks/DWM Mini [Link] 9/40


4/19/2019 DWM Mini Project

In [42]: [Link](figsize=(10,10))
[Link](y = data["season"],hue=data["league"],
palette=["r","g","b","c","lime","m","y","k","gold","orange"])
[Link]("MATCHES PLAYED IN EACH LEAGUE BY SEASON")
[Link]()

In [43]: #Merge team data


data = [Link](teams,left_on="home_team_api_id",right_on="team_api_id",how="le
data = [Link](["id","team_api_id",'team_fifa_api_id'],axis = 1)
data = [Link](columns={ 'team_long_name':"home_team_lname",'team_short_name
[Link]

Out[43]: Index(['country_id', 'league_id', 'season', 'stage', 'date', 'match_api_id',


'home_team_api_id', 'away_team_api_id', 'home_team_goal',
'away_team_goal', 'country', 'league', 'year', 'home_team_lname',
'home_team_sname'],
dtype='object')

localhost:8888/notebooks/DWM Mini [Link] 10/40


4/19/2019 DWM Mini Project

In [44]: data = [Link](teams,left_on="away_team_api_id",right_on="team_api_id",how="le


data = [Link](["id","team_api_id",'team_fifa_api_id'],axis = 1)
data = [Link](columns={ 'team_long_name':"away_team_lname",'team_short_name
[Link]

Out[44]: Index(['country_id', 'league_id', 'season', 'stage', 'date', 'match_api_id',


'home_team_api_id', 'away_team_api_id', 'home_team_goal',
'away_team_goal', 'country', 'league', 'year', 'home_team_lname',
'home_team_sname', 'away_team_lname', 'away_team_sname'],
dtype='object')

localhost:8888/notebooks/DWM Mini [Link] 11/40


4/19/2019 DWM Mini Project

In [45]: h_t = [Link]("home_team_lname")["home_team_goal"].sum().reset_index()


a_t = [Link]("away_team_lname")["away_team_goal"].sum().reset_index()
h_t = h_t.sort_values(by="home_team_goal",ascending= False)
a_t = a_t.sort_values(by="away_team_goal",ascending= False)
[Link](figsize=(13,10))
[Link](121)
ax = [Link](y="home_team_lname",x="home_team_goal",
data=h_t[:20],palette="summer",
linewidth = 1,edgecolor = "k"*20)
[Link]('')
[Link]("top teams by home goals")
for i,j in enumerate(h_t["home_team_goal"][:20]):
[Link](.7,i,j,weight = "bold")
[Link](122)
ax = [Link](y="away_team_lname",x="away_team_goal",
data=a_t[:20],palette="winter",
linewidth = 1,edgecolor = "k"*20)
[Link]("")
plt.subplots_adjust(wspace = .4)
[Link]("top teams by away goals")
for i,j in enumerate(a_t["away_team_goal"][:20]):
[Link](.7,i,j,weight = "bold")

localhost:8888/notebooks/DWM Mini [Link] 12/40


4/19/2019 DWM Mini Project

In [46]: x = h_t
x = [Link](columns={'home_team_lname':"team", 'home_team_goal':"goals"})
y = a_t
y = [Link](columns={'away_team_lname':"team", 'away_team_goal':"goals"})
goals = [Link]([x,y])
goals = [Link]("team")["goals"].sum().reset_index().sort_values(by = "goal
[Link](figsize=(9,14))
ax = [Link](x="goals",y="team",
data=goals[:30],palette="rainbow",
linewidth = 1,edgecolor = "k"*30)
for i,j in enumerate(goals["goals"][:30]):
[Link](.3,i,j,weight="bold",color = "k",fontsize =12)
[Link]("Teams with highest total goals ")
[Link]()

localhost:8888/notebooks/DWM Mini [Link] 13/40


4/19/2019 DWM Mini Project

localhost:8888/notebooks/DWM Mini [Link] 14/40


4/19/2019 DWM Mini Project

In [47]: x = [Link]("home_team_lname")["match_api_id"].count().reset_index()
x = [Link](columns={"home_team_lname":"team"})
y = [Link]("away_team_lname")["match_api_id"].count().reset_index()
y = [Link](columns={"away_team_lname":"team"})
xy = [Link]([x,y],axis=0)
match_teams = [Link]("team")["match_api_id"].sum().reset_index().sort_values
match_teams = match_teams.rename(columns={"match_api_id":"matches_played"})
match_teams[:20]

Out[47]:
team matches_played

51 Chelsea 304

22 Athletic Club de Bilbao 304

186 Paris Saint-Germain 304

256 Sunderland 304

180 Olympique de Marseille 304

179 Olympique Lyonnais 304

255 Stoke City 304

83 FC Lorient 304

273 Valencia CF 304

168 Málaga CF 304

167 Motherwell 304

75 FC Barcelona 304

162 Manchester United 304

49 Celtic 304

161 Manchester City 304

262 Tottenham Hotspur 304

158 Liverpool 304

70 Everton 304

252 Stade Rennais FC 304

144 Kilmarnock 304

localhost:8888/notebooks/DWM Mini [Link] 15/40


4/19/2019 DWM Mini Project

In [49]: [Link](figsize=(12,6))
[Link](data["home_team_goal"],shade=True,
color="b",label="home goals")
[Link](data["away_team_goal"],shade=True,
color="r",label="away goals")
[Link](data["home_team_goal"].mean(),linestyle = "dashed",
color="b",label="home goals mean")
[Link](data["away_team_goal"].mean(),linestyle = "dashed",
color="r",label="away goals mean")
[Link](loc="best",prop = {"size" : 12})
[Link]("DISTRIBUTION OF HOME AND AWAY GOALS")
[Link]("goals")
[Link]()

localhost:8888/notebooks/DWM Mini [Link] 16/40


4/19/2019 DWM Mini Project

In [50]: x = [Link](["home_team_lname","league"]).agg({"match_api_id":"count","home_
y = [Link](["away_team_lname","league"]).agg({"match_api_id":"count","away_
x = [Link](columns={'home_team_lname':"team", 'match_api_id':"matches", 'home_t
y = [Link](columns={'away_team_lname':"team", 'match_api_id':"matches", 'away_t
xy = [Link]([x,y])
xy = [Link](["team","league"])[["matches","goals"]].sum().reset_index()
xy = xy.sort_values(by="goals",ascending=False)
[Link](figsize=(13,6))
c = ["r","g","b","m","y","yellow","c","orange","grey","lime","white"]
lg = xy["league"].unique()
for i,j,k in itertools.zip_longest(lg,range(len(lg)),c):
[Link]("matches","goals",data=xy[xy["league"] == i],label=[i],s=100,alph
[Link](loc="best")
[Link]("MATCHES")
[Link]("GOALS SCORED")

[Link]("MATCHES VS GOALS BY TEAMS")


[Link]()

localhost:8888/notebooks/DWM Mini [Link] 17/40


4/19/2019 DWM Mini Project

In [51]: data["total_goal"] = data["home_team_goal"]+data["away_team_goal"]


a = [Link]("season").agg({"total_goal":"sum"})
m = [Link]("season").agg({"total_goal":"mean"})
s = [Link]("season").agg({"total_goal":"std"})
x = [Link]("season").agg({"total_goal":"max"})
xx = [Link](m,left_index=True,right_index=True,how="left")
yy = [Link](x,left_index=True,right_index=True,how="left")
x_y = [Link](yy,left_index=True,right_index=True,how="left").reset_index()
x_y = x_y.rename(columns={'total_goal_x_x':"goals", 'total_goal_y_x':"mean",
'total_goal_x_y':"std",'total_goal_y_y':"max"})
import itertools
cols = [ 'goals', 'mean', 'std', 'max' ]
length = len(cols)
cs = ["r","g","b","c"]
[Link](figsize=(12,16))

for i,j,k in itertools.zip_longest(cols,range(length),cs):


[Link](length,length/length,j+1)
[Link](x_y["season"],x_y[i],color=k)
[Link](i)
plt.subplots_adjust(hspace =.3)

localhost:8888/notebooks/DWM Mini [Link] 18/40


4/19/2019 DWM Mini Project

localhost:8888/notebooks/DWM Mini [Link] 19/40


4/19/2019 DWM Mini Project

In [54]: import networkx as nx


g = nx.from_pandas_edgelist(data,"home_team_sname","away_team_sname")
fig = [Link](figsize=(11,11))
nx.draw_kamada_kawai(g,with_labels = True)
[Link]("INTERACTION BETWEEN TEAMS")
fig.set_facecolor("white")

In [55]: #create new feature for winning team


def label(data):
if data["home_team_goal"] > data["away_team_goal"]:
return data["home_team_lname"]
elif data["away_team_goal"] > data["home_team_goal"]:
return data["away_team_lname"]
elif data["home_team_goal"] == data["away_team_goal"]:
return "DRAW"

In [56]: data["win"] = [Link](lambda data:label(data),axis=1)

localhost:8888/notebooks/DWM Mini [Link] 20/40


4/19/2019 DWM Mini Project

In [57]: #create new feature for outcome of match


def lab(data):
if data["home_team_goal"] > data["away_team_goal"]:
return "HOME TEAM WIN"
elif data["away_team_goal"] > data["home_team_goal"]:
return "AWAY TEAM WIN"
elif data["home_team_goal"] == data["away_team_goal"]:
return "DRAW"

In [58]: data["outcome_side"] = [Link](lambda data:lab(data),axis = 1)

In [59]: #create new feature for losing team


def labe(data):
if data["home_team_goal"] < data["away_team_goal"]:
return data["home_team_lname"]
elif data["away_team_goal"] < data["home_team_goal"]:
return data["away_team_lname"]
elif data["home_team_goal"] == data["away_team_goal"]:
return "DRAW"

In [60]: data["lost"] = [Link](lambda data:labe(data),axis=1)

localhost:8888/notebooks/DWM Mini [Link] 21/40


4/19/2019 DWM Mini Project

In [61]: [Link](figsize=(8,8))
data["outcome_side"].value_counts().[Link](autopct = "%1.0f%%",
colors =sns.color_palette("rainbow",
wedgeprops = {"linewidth":2,"edgecol
my_circ = [Link]((0,0),.7,color = "white")
[Link]().add_artist(my_circ)
[Link]("PROPORTION OF GAME OUTCOMES")
[Link]()

localhost:8888/notebooks/DWM Mini [Link] 22/40


4/19/2019 DWM Mini Project

In [62]: win = data["win"].value_counts()[1:].reset_index()


lost = data["lost"].value_counts()[1:].reset_index()
[Link](figsize=(13,14))
[Link](121)
ax = [Link](win["win"][:30],win["index"][:30],
palette="Set2",
linewidth = 1,edgecolor = "k"*30)
[Link](" TOP WINNING TEAMS")
[Link]("")
for i,j in enumerate(win["win"][:30]):
[Link](.7,i,j,color = "black",weight = "bold")

[Link](122)
ax = [Link](lost["lost"][:30],lost["index"][:30],
palette="Set2",
linewidth = 1,edgecolor = "k"*30)
[Link](" TOP TEAMS that Lost")
plt.subplots_adjust(wspace = .3)
[Link]("")
for i,j in enumerate(lost["lost"][:30]):
[Link](.7,i,j,color = "black",weight = "bold")

localhost:8888/notebooks/DWM Mini [Link] 23/40


4/19/2019 DWM Mini Project

In [63]: #merge win,draw and lost data of team to matches played


f = [Link](win,left_on="team",right_on="index",how="left")
f = [Link]("index",axis =1)
f = [Link](columns={"outcome":"wins"})
f = [Link](lost,left_on="team",right_on="index",how="left")
f = [Link]("index",axis =1)
dr = data[data["outcome_side"] == "DRAW"][["home_team_lname","away_team_lname"]]
l = dr["home_team_lname"].value_counts().reset_index()
v = dr["away_team_lname"].value_counts().reset_index()
l = [Link](columns={'index':"team", 'home_team_lname':"draw"})
v = [Link](columns={'index':"team", 'away_team_lname':"draw"})
lv = [Link]([l,v])
lv = [Link]("team")["draw"].sum().reset_index()
f = [Link](lv,left_on="team",right_on="team",how ="left")

In [64]: f = f.sort_values(by="goals",ascending=False)
f_new = [Link]()
f_new.index = f_new.team
f_new[["win","lost","draw"]][:20].plot(kind = "bar",figsize=(13,5),
stacked =True,linewidth = 1,
edgecolor = "k"*20
)
[Link](loc="best",prop = {"size" : 13})
[Link]("PERFORMANCE BY TOP TEAMS")
[Link]("matches played")
[Link]()

localhost:8888/notebooks/DWM Mini [Link] 24/40


4/19/2019 DWM Mini Project

In [65]: x = [Link]([Link](["league","win"])["win"].count())
x = [Link](columns={"win":"team"}).reset_index()
x = [Link](columns={"win":"team","team":"win"})
x = x.sort_values(by="win",ascending=False)
x = x[x["team"] != "DRAW"]
x = x.drop_duplicates(subset=["league"],keep="first")
[Link](figsize=(8,7))
ax =[Link](x["win"],x["league"],palette="cool",
linewidth = 1 ,edgecolor = "k"*10)
for i,j in enumerate(x["team"]):
[Link](.7,i,j,weight = "bold",fontsize = 12)
[Link]("TOP TEAMS BY LEAGUES")
[Link]()

localhost:8888/notebooks/DWM Mini [Link] 25/40


4/19/2019 DWM Mini Project

In [66]: [Link](["league"]).agg({"match_api_id":"count","total_goal":"sum"}).plot(ki
st
fi
li
ed
)
[Link]("# MATCHES PLAYED IN EACH LEAGUE VS TOTAL GOALS SCORED")
[Link]()

localhost:8888/notebooks/DWM Mini [Link] 26/40


4/19/2019 DWM Mini Project

In [67]: [Link](figsize=(7,15))
[Link](211)
agg = [Link](["league"]).agg({"match_api_id":"count","total_goal":"sum"})
agg["match_api_id"].[Link](colors=sns.color_palette("seismic",10),
autopct="%1.0f%%",
wedgeprops={"linewidth":2,"edgecolor":"white"})
[Link]("")
my_circ = [Link]((0,0),.7,color ="white")
[Link]().add_artist(my_circ)
[Link]("PROPORTION OF MATCHES PLAYED IN LEAGUES")
[Link](212)
agg["total_goal"].[Link](colors=sns.color_palette("seismic",10),
autopct="%1.0f%%",
wedgeprops={"linewidth":2,"edgecolor":"white"})
[Link]("")
my_circ = [Link]((0,0),.7,color ="white")
[Link]().add_artist(my_circ)
[Link]("PROPORTION OF GOALS SCORED IN LEAGUES")
[Link]()

localhost:8888/notebooks/DWM Mini [Link] 27/40


4/19/2019 DWM Mini Project

localhost:8888/notebooks/DWM Mini [Link] 28/40


4/19/2019 DWM Mini Project

In [68]: pvt = pd.pivot_table(index="season",columns="league",values="total_goal",data=dat


[Link](kind = "barh",stacked = True,figsize =(10,8),
colors =sns.color_palette("rainbow",11),
linewidth = .5,edgecolor = ["grey"]*10)
[Link]("GOALS SCORED IN EACH SEASON OF LEAUGES")
[Link]()

localhost:8888/notebooks/DWM Mini [Link] 29/40


4/19/2019 DWM Mini Project

In [69]: i = data["win"].value_counts()[1:25].index
t= pd.pivot_table(index="home_team_lname",columns="season",values="home_team_goal
data=data,aggfunc="sum")
t=t[[Link](i)]
[Link](kind="barh",stacked=True,figsize=(10,10),colors=sns.color_palette("prism",
[Link]("HOME GOALS SCORED BY TOP TEAMS BY SEASON")
[Link]()

localhost:8888/notebooks/DWM Mini [Link] 30/40


4/19/2019 DWM Mini Project

In [70]: i = data["win"].value_counts()[1:25].index
t= pd.pivot_table(index="away_team_lname",columns="season",
values="away_team_goal",data=data,aggfunc="sum")
t=t[[Link](i)]
[Link](kind="barh",stacked=True,figsize=(10,10),colors=sns.color_palette("prism",
[Link]("HOME GOALS SCORED BY TOP TEAMS BY SEASON")
[Link]()

localhost:8888/notebooks/DWM Mini [Link] 31/40


4/19/2019 DWM Mini Project

In [71]: nw = data[["season","league","win"]]
nw["team"] = nw["win"]
nw = [Link](["season","league","team"])["win"].count().reset_index().sort_val
nw = nw[nw["team"] != "DRAW"]
nw = nw.drop_duplicates(subset=["season","league"],keep="first").sort_values(by=

[Link](figsize=(13,28))
[Link](621)
lg = nw[nw["league"] == "Belgium Jupiler League"]
ax = [Link](lg["win"],lg["season"],palette="cool",
linewidth = 1 ,edgecolor = "k"*lg["season"].nunique())
for i,j in enumerate(lg["team"]):
[Link](.7,i,j,weight = "bold")
[Link]("Belgium Jupiler League")
[Link]("")
[Link]("")

[Link](622)
lg = nw[nw["league"] == "England Premier League"]
ax = [Link](lg["win"],lg["season"],palette="magma",
linewidth = 1 ,edgecolor = "k"*lg["season"].nunique())
for i,j in enumerate(lg["team"]):
[Link](.7,i,j,weight = "bold",color="white")
[Link]("England Premier League")
[Link]("")
[Link]("")

[Link](623)
lg = nw[nw["league"] == 'Spain LIGA BBVA']
ax = [Link](lg["win"],lg["season"],palette="rainbow",
linewidth = 1 ,edgecolor = "k"*lg["season"].nunique())
for i,j in enumerate(lg["team"]):
[Link](.7,i,j,weight = "bold")
[Link]('Spain LIGA BBVA')
[Link]("")
[Link]("")

[Link](624)
lg = nw[nw["league"] == 'France Ligue 1']
ax = [Link](lg["win"],lg["season"],palette="summer",
linewidth = 1 ,edgecolor = "k"*lg["season"].nunique())
for i,j in enumerate(lg["team"]):
[Link](.7,i,j,weight = "bold",color = "white")
[Link]('France Ligue 1')
[Link]("")
[Link]("")

[Link](625)
lg = nw[nw["league"] == 'Germany 1. Bundesliga']
ax = [Link](lg["win"],lg["season"],palette="winter",
linewidth = 1 ,edgecolor = "k"*lg["season"].nunique())
for i,j in enumerate(lg["team"]):
[Link](.7,i,j,weight = "bold")
[Link]('Germany 1. Bundesliga')
[Link]("")
[Link]("")

localhost:8888/notebooks/DWM Mini [Link] 32/40


4/19/2019 DWM Mini Project

[Link](626)
lg = nw[nw["league"] == 'Italy Serie A']
ax = [Link](lg["win"],lg["season"],palette="husl",
linewidth = 1 ,edgecolor = "k"*lg["season"].nunique())
for i,j in enumerate(lg["team"]):
[Link](.7,i,j,weight = "bold")
[Link]('Italy Serie A')
[Link]("")
[Link]("")
[Link]()

localhost:8888/notebooks/DWM Mini [Link] 33/40


4/19/2019 DWM Mini Project

In [72]: [Link](figsize=(13,28))
[Link](621)
lg = nw[nw["league"] == 'Netherlands Eredivisie']
ax = [Link](lg["win"],lg["season"],palette="Blues",
linewidth = 1 ,edgecolor = "k"*lg["season"].nunique())
for i,j in enumerate(lg["team"]):
[Link](.7,i,j,weight = "bold")
[Link]('Netherlands Eredivisie')
[Link]("")
[Link]("")

[Link](622)
lg = nw[nw["league"] == 'Poland Ekstraklasa']
ax = [Link](lg["win"],lg["season"],palette="winter",
linewidth = 1 ,edgecolor = "k"*lg["season"].nunique())
for i,j in enumerate(lg["team"]):
[Link](.7,i,j,weight = "bold")
[Link]('Poland Ekstraklasa')
[Link]("")
[Link]("")

[Link](623)
lg = nw[nw["league"] == 'Portugal Liga ZON Sagres']
ax = [Link](lg["win"],lg["season"],palette="rainbow",
linewidth = 1 ,edgecolor = "k"*lg["season"].nunique())
for i,j in enumerate(lg["team"]):
[Link](.7,i,j,weight = "bold")
[Link]('Portugal Liga ZON Sagres')
[Link]("")
[Link]("")

[Link](624)
lg = nw[nw["league"] == 'Scotland Premier League']
ax = [Link](lg["win"],lg["season"],palette="Greens",
linewidth = 1 ,edgecolor = "k"*lg["season"].nunique())
for i,j in enumerate(lg["team"]):
[Link](.7,i,j,weight = "bold")
[Link]('Scotland Premier League')
[Link]("")
[Link]("")

[Link](625)
lg = nw[nw["league"] == 'Switzerland Super League']
ax = [Link](lg["win"],lg["season"],palette="cool",
linewidth = 1 ,edgecolor = "k"*lg["season"].nunique())
for i,j in enumerate(lg["team"]):
[Link](.7,i,j,weight = "bold")
[Link]('Switzerland Super League')
[Link]("")
[Link]("")
[Link]()

localhost:8888/notebooks/DWM Mini [Link] 34/40


4/19/2019 DWM Mini Project

localhost:8888/notebooks/DWM Mini [Link] 35/40


4/19/2019 DWM Mini Project

In [73]: [Link](figsize=(8,14))
ax = [Link](y=nw["team"],order=nw["team"].value_counts().index,
palette="plasma",linewidth = 1 ,edgecolor = "k"*nw["team"].nun
[Link]("TOP LEAGUE WINNERS")
for i,j in enumerate(nw["team"].value_counts().values):
[Link](.2,i,j,color = "white",weight="bold")

localhost:8888/notebooks/DWM Mini [Link] 36/40


4/19/2019 DWM Mini Project

In [74]: player
player["weight_kg"] = player["weight"] * 0.453592
player["height_m"] = player["height"] / 100
player["bmi"] = player["weight_kg"]/(player["height_m"] * player["height_m"
player["year"] = [Link](player["birthday"]).year
player["age"] = 2018 - player["year"]

cols = ["bmi","weight_kg","height_m","age"]
length = len(cols)
c = ["b","r","g","c"]
[Link](figsize=(13,17))
for i,j,k in itertools.zip_longest(cols,range(length),c):
[Link](4,1,j+1)
player[i].plot(color = k ,linewidth =.2,label = i)
[Link](player[i].mean(),color = "k",linestyle = "dashed",label="mean")
[Link](loc="best")
plt.subplots_adjust(hspace = .3)
[Link]("player index")
[Link](i)
[Link](i)

localhost:8888/notebooks/DWM Mini [Link] 37/40


4/19/2019 DWM Mini Project

localhost:8888/notebooks/DWM Mini [Link] 38/40


4/19/2019 DWM Mini Project

In [75]: cols = ["bmi","weight_kg","height_m","age"]


length = len(cols)
c = ["b","r","k","c"]
[Link](figsize=(13,10))

for i,j,k in itertools.zip_longest(cols,range(length),c):


[Link](2,2,j+1)
[Link](player[i],color=k)
[Link](player[i].mean(),color = "k",linestyle = "dashed",label="mean")
[Link](loc="best")
[Link](i)
[Link]("")

localhost:8888/notebooks/DWM Mini [Link] 39/40


4/19/2019 DWM Mini Project

In [76]: #Extract year


player["year"] = [Link](player["birthday"]).year
#extract age
player["age"] = 2018 - player["year"]

print ("PLAYER ATTRIBUTES")


print ("=========================================================================
print ("Oldest Player is",[Link][player["age"].idxmax()]["player_name"],"of a
print ("Youngest Players are",list(player[player["age"]==19]["player_name"]),"of
print ("Tallest Player is",[Link][player["height_m"].idxmax()]["player_name"
print ("Shortest Player is",[Link][player["height_m"].idxmin()]["player_name"
print ("Player with highest weight are",list(player[player["weight_kg"] == 110.22
print ("Player with lowest weight is",[Link][player["weight_kg"].idxmin()]["p
print ("Player with Highest Body Mass Index is",[Link][player["bmi"].idxmax()
print ("Player with lowest Body Mass Index is",[Link][player["bmi"].idxmin()

PLAYER ATTRIBUTES
===============================================================================
====================
Oldest Player is Alberto Fontana of age 51 years
Youngest Players are ['Alban Lafont', 'Gianluigi Donnarumma', 'Jonathan Leko']
of age 19 years
Tallest Player is Kristof van Hout of height 2.0828 meters
Shortest Player is Juan Quero of height 1.5748 meters
Player with highest weight are ['Kristof van Hout', 'Tim Wiese'] of height 110.
222856 kilograms
Player with lowest weight is Juan Quero of height 53.070264 kilograms
Player with Highest Body Mass Index is Sylvan Ebanks-Blake of 30.86570247534958
6 kg/m2
Player with lowest Body Mass Index is John Stewart of 17.58956425144406 kg/m2

In [ ]:

localhost:8888/notebooks/DWM Mini [Link] 40/40

You might also like