Skip to main content

A Python package to scrape shots data from understat.com for either a single game or a whole season.

Project description

understatscraper

A Python package to scrape shots data from understat.com for either a single game or a whole season.

Author: Shivank Batra(@prstrggr)

Installation

Use the package manager pip to install understatscraper.

pip install understatscraper

Usage

Scraping Data For A Single Game

You can get shots data for a single game by calling the single_match() method of the Understat class.

The function takes one single parameter which is the match id(int) of the game. Match id of the game can be found in the url at the end. Here we have taken the example of Liverpool-Leeds game:

from understatscraper import Understat

# creating an instance of the class Understat
understat = Understat()

#Calling the function to scrape data for a specific game id 16414
#returns a dataframe containing all the shots data from the game
df = understat.single_match(16414)
print(df)

Scraping Data For A Whole Season

You can get shots data for a whole season and for a specified league by calling the season() method of the Understat class.

It takes four parameters:

  1. league(str)
  2. year(int)
  3. team(str). Default value as None.
  4. player(str). Default value as None.

NOTE:

  1. Before calling the season function, make sure to download this csv file since it will used as a reference point to easily loop over the match ids according to the specified user input when calling the function.

  2. If you want the data for let's say 20/21 season then input the preceding year i.e. 2020 as the year parameter to get the data for 20/21 season.

  3. Data is available from the 2014 -2015 to 2021-2022 season.

  4. Data for the 2021-2022 is only available till Gameweek 4.

  5. Data is only available for five leagues:

    1. EPL
    2. La liga
    3. Ligue 1
    4. Bundesliga
    5. Serie A
  6. Input 'La liga' as the league parameter with a smaller case l in liga when wanting the data for LaLiga. Similarly, for Premier league, input 'EPL'.

from understatscraper import Understat

# creating an instance of the class Understat
understat = Understat()

#calling a function to scrape shots data for the EPL season 20/21
#returns a dataframe containing all the shots data from the EPL season 20/21
df = understat.season('EPL', 2020)
print(df)

#calling a function to scrape shots data for Raheem Sterling from the 20/21 EPL season.
df = understat.season('EPL', 2020, team='Manchester City', player='Raheem Sterling')
print(df)

NOTE:

While inputting the team and player, make sure to input exact team and player name that is available on understat.com

Contributing

For any doubts or suggestions you can contact me here

License

MIT

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for understatscraper, version 0.0.2
Filename, size File type Python version Upload date Hashes
Filename, size understatscraper-0.0.2.tar.gz (3.9 kB) File type Source Python version None Upload date Hashes View
Filename, size understatscraper-0.0.2-py3-none-any.whl (4.7 kB) File type Wheel Python version py3 Upload date Hashes View

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring Facebook / Instagram Facebook / Instagram PSF Sponsor Fastly Fastly CDN Google Google Object Storage and Download Analytics Huawei Huawei PSF Sponsor Microsoft Microsoft PSF Sponsor NVIDIA NVIDIA PSF Sponsor Pingdom Pingdom Monitoring Salesforce Salesforce PSF Sponsor Sentry Sentry Error logging StatusPage StatusPage Status page