Skip to main content

A Python package to parse StatsBomb JSON data to CSV

Project description

StatsBomb JSON parser

PyPI version PyPI - Python Version Build Status codecov HitCount

Convert competitions/matches/lineups/events JSON data released by StatsBomb into easy to use CSV format.

Installation

$ pip install statsbomb

Unit tests

To run the unit tests for this package:

$ python -m pytest tests/

Example usage

  • Parsing the competitions.json file:
import statsbomb as sb

# path to where the StatsBomb data is stored
comps = sb.Competitions('../../open-data/data/competitions.json')
print(len(comps))  # 3

df = comps.get_dataframe()
print(df)
competition_id competition_name country_name match_available match_updated season_id season_name
37 FA Women's Super League England 2018-09-08T07:33:39.356340 2018-09-08T07:33:39.356340 1 2017/2018
43 FIFA World Cup International 2018-09-08T07:33:39.356340 2018-09-08T14:30:04.356514 3 2018
49 NWSL United States of America 2018-09-08T07:33:39.356340 2018-09-08T07:33:39.356340 3 2018
  • Parsing an events json file to extract shots:
import statsbomb as sb

events = sb.Events('../../open-data/data/events/8658.json')
df = events.get_dataframe(event_type='shot')
print(len(df))  # 23

print(df)
event_type id index period timestamp minute second possession possession_team play_pattern off_camera team player position duration under_pressure statsbomb_xg key_pass_id body_part type outcome technique first_time follows_dribble redirect one_on_one open_goal deflected start_location_x start_location_y end_location_x end_location_y end_location_z
shot c3ffbb5f-d836-4d33-a02a-3a994990d253 577 1 00:20:51.227 20 51 39 Croatia From Free Kick False Croatia Domagoj Vida Left Center Back 1.013 0.05478843 baafd0a9-1031-46df-82a2-16538d6e94cf Head Open Play Off T Normal 112.0 49.0 119.0 36.7 4.7
shot d7a727de-1b60-47c7-b9fa-10948bb730ed 634 1 00:23:34.907 23 34 45 Croatia From Free Kick False Croatia Ivan Rakitić Left Center Midfield 2.053 0.04375982 9cc48e31-5a52-4074-97b1-5c3eafdd753d Left Foot Open Play Off T Volley 108.0 29.0 120.0 46.9 6.1
shot 20bcdb94-9507-4bed-8315-edddcbb84081 736 1 00:27:53.880 27 53 53 Croatia From Free Kick False Croatia Ivan Perišić Left Wing 0.587 0.12172278 90fdf286-3e32-4646-bcb1-a83a7d51593f Left Foot Open Play Goal Half Volley True True 105.0 32.0 120.0 43.3 0.7
... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ...

Project details


Download files

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

Source Distribution

statsbomb-0.1.3.tar.gz (4.4 kB view details)

Uploaded Source

Built Distribution

statsbomb-0.1.3-py3-none-any.whl (5.0 kB view details)

Uploaded Python 3

File details

Details for the file statsbomb-0.1.3.tar.gz.

File metadata

  • Download URL: statsbomb-0.1.3.tar.gz
  • Upload date:
  • Size: 4.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.11.0 pkginfo/1.4.2 requests/2.19.1 setuptools/39.0.1 requests-toolbelt/0.8.0 tqdm/4.19.1 CPython/3.6.5

File hashes

Hashes for statsbomb-0.1.3.tar.gz
Algorithm Hash digest
SHA256 8466ecc487b19656416782ed17fe9d9ea186a36a457e2702066ad2a9a1a3e934
MD5 b48a8825ddaef0e332e2df49f8b55a84
BLAKE2b-256 4ebe3067835f3e92e1df606ea652e1b8ebdab394fc0f40f26e76b4e22af5e180

See more details on using hashes here.

File details

Details for the file statsbomb-0.1.3-py3-none-any.whl.

File metadata

  • Download URL: statsbomb-0.1.3-py3-none-any.whl
  • Upload date:
  • Size: 5.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.11.0 pkginfo/1.4.2 requests/2.19.1 setuptools/39.0.1 requests-toolbelt/0.8.0 tqdm/4.19.1 CPython/3.6.5

File hashes

Hashes for statsbomb-0.1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 4128c53a397c779c280a873171b5eaee9cce3bdf42bb4b74203fe3226720b503
MD5 886ae53f4d898fb29ec464340776d9f2
BLAKE2b-256 46a1f3f9e37529a28890aea0b19066a5052f48a0edacff50d7467034d2c2e3fc

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page