GithubHelp home page GithubHelp logo

korfanakis / football_match_summary_report Goto Github PK

View Code? Open in Web Editor NEW
3.0 1.0 1.0 2.92 MB

A short tutorial on using Python to extract football data from Understat and visualise a football match's summary (shot map + stats).

License: MIT License

Python 100.00%
python matplotlib requests beautifulsoup4 football football-data football-analytics shotmap premier-league

football_match_summary_report's Introduction

Football Match Summary Report ⚽📈

Render With Made with Made with and Licence Star if useful


Match report for the game between Chelsea and Liverpool that took place on the 2nd of January, 2022.


Table of Contents:


Overview

This repository contains Python code for:

  • Web scraping a football match from Understat, and
  • Creating a figure that summarises that particular match. Specifically, the final figure displays various stats (e.g. goals, shots, shots on target, xG, etc.) on top of a shot map for both the home and away teams.

For now, we are limited to matches from the English Premier League. However, we can easily expand to other leagues by adding a few lines of code and including the crests for the additional teams in the designated folder.


Code Organisation

The code is organised into three different Python scripts:

  • draw_football_pitch.py: As the name suggests, this file contains a function for visualising a football pitch. It is extracted from the article ‘How to Draw a Football Pitch’ by McKeever (accessed 17-01-2022). The only modification is not showing the two penalty spots as they can easily get confused with missed shots in the final figure.

  • match_scraper.py: The second file contains a collection of functions for extracting the data (shots and goals) and various information used for the final figure (e.g. stat summary, headline, date, etc.).

  • match_visualisation.py: The final Python file contains the function (create_figure()) for creating the figure. Notice that the function requires three arguments: the ID of the game we want to visualise and the figure and axes objects of the plot.

The repository also contains a Jupyter notebook that demonstrates how to run the code and create the figure. Also, please refer to my Kaggle notebook for a better walkthrough of the code.


Requirements

Python Version: 3.6.8
Packages: numpy (1.19.5), pandas (1.1.5), matplotlib (3.3.4), json (2.0.9), requests (2.25.1), bs4 (4.9.3).


Acknowledgements

All data used in this tutorial are extracted from Understat's website. The final design of our figure has been influenced by various sources such as The Analyst (for example, see this tweet), Stats Perform, and Sport24.gr


Extra Resources

[1] How to Draw a Football Pitch by Peter McKeever (Accessed: 17/01/2022)

[2] Shot Maps by McKay Johns (Accessed: 18/01/2022)

[3] Understat Series : Shotmaps by José González (Accessed: 10/01/2022)

football_match_summary_report's People

Contributors

korfanakis avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar

Forkers

gyracat

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.