Note: UnderStat website contains only league matches data, not UEFA Champions league or International matches.
This notebook contains a code scrapes the data for a single player from understat.com website, which provides a statistical data for the top 5 leagues from 2014/2015 season until now. You can scrape all the data you need by only passing the player id from the website, and then this notebook will do it all. To accomplish my work, I have used some sources I'll mention them lately.
To explain my code, I'll use the Egyptian king "Mohamed Salah" as an example:
After passing the player id, there are many functions to find and filter the data you want:
1- GetMatchesData():
this function returns a csv. file contains all the matches played for this player in the top 5 leagues since 2014/2015 season with match details and the player performance in this match.
Scraped table from the website:
Output table:
2- PlayerSeasonStats():
This function focuses on a particular season entered by the user, and gives output as below:
3- PlayerCareerStats():
This function returns as csv. file with the summary statistics for every season like below:
4- TabularShotsData():
This function scrapes the intetractive shotmap in the website and returns it in a csv. file:
5- TimeTier():
This function filter the shots by the time interval, which was set for every 15 minutes.
The output:
6- xGTier():
This function filter the shots by the shot quality, which was set using the table below:
The output:
7- ShotsArea():
This function returns a csv. file with the shot zones filtered by season.
The output:
8- PlotShots()
This function recreates the interactive shot map using mplsoocer package
9- KeyPassers()
This function displays the top key passers for the player, and returns the output in a csv. file
The Output:
10- KeyPassTypes()
This function displays the top key pass types, and returns the output in a csv. file.
The Output:
Sources:
-
How to scrape Understat for football data in Python with requests and BeautifulSoup - McKay Johns (YouTube) https://youtu.be/IsR5FrjNmro
-
How to create football shot maps in python - McKay Johns (YouTube) https://youtu.be/2RhTuRWNqUc
-
mplsoccer package documentaion https://mplsoccer.readthedocs.io/en/latest/index.html#
-
من أين تأتي الأهداف؟ - سبورت 360 عربية(YouTube) https://www.youtube.com/watch?v=KOaJ6RFACrU