Statsbomb¶
Load local files¶
In [1]:
Copied!
from kloppy import statsbomb
dataset = statsbomb.load(
event_data="../../kloppy/tests/files/statsbomb_3788741_event.json",
lineup_data="../../kloppy/tests/files/statsbomb_3788741_lineup.json",
# 360 file is optional
three_sixty_data="../../kloppy/tests/files/statsbomb_3788741_360.json",
# Optional arguments
coordinates="statsbomb",
event_types=["pass", "shot"]
)
dataset.to_df().head()
from kloppy import statsbomb
dataset = statsbomb.load(
event_data="../../kloppy/tests/files/statsbomb_3788741_event.json",
lineup_data="../../kloppy/tests/files/statsbomb_3788741_lineup.json",
# 360 file is optional
three_sixty_data="../../kloppy/tests/files/statsbomb_3788741_360.json",
# Optional arguments
coordinates="statsbomb",
event_types=["pass", "shot"]
)
dataset.to_df().head()
Out[1]:
event_id | event_type | result | success | period_id | timestamp | end_timestamp | ball_state | ball_owning_team | team_id | player_id | coordinates_x | coordinates_y | end_coordinates_x | end_coordinates_y | receiver_player_id | set_piece_type | body_part_type | pass_type | |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
0 | bbc398f7-c784-4958-a504-37b583caf97a | PASS | COMPLETE | True | 1 | 0.878 | 2.788504 | alive | 909 | 909 | 11086 | 59.95 | 39.95 | 32.45 | 28.75 | 8963 | KICK_OFF | RIGHT_FOOT | NaN |
1 | 5c210f79-9714-44a6-b2ec-387f6a117b37 | PASS | COMPLETE | True | 1 | 4.288 | 6.764772 | alive | 909 | 909 | 8963 | 36.15 | 30.35 | 70.65 | 75.75 | 8541 | NaN | LEFT_FOOT | LONG_BALL |
2 | 8a3e6668-9680-4417-987e-8db0c6ce6a8b | PASS | COMPLETE | True | 1 | 12.163 | 14.093230 | alive | 914 | 914 | 8286 | 43.05 | 0.05 | 15.75 | 7.45 | 6954 | THROW_IN | NaN | NaN |
3 | f8e61bb0-b618-4695-9ff9-eaa0584bdbfa | PASS | COMPLETE | True | 1 | 16.420 | 18.242108 | alive | 914 | 914 | 6954 | 3.25 | 12.65 | 7.85 | 36.15 | 7036 | NaN | RIGHT_FOOT | NaN |
4 | 1d72ce76-31fd-43e0-a6b2-1f78c8a57a77 | PASS | COMPLETE | True | 1 | 20.025 | 21.071484 | alive | 914 | 914 | 7036 | 9.05 | 38.85 | 19.65 | 47.85 | 7173 | NaN | RIGHT_FOOT | NaN |
Load remote files¶
You can also directly read files from urls (http or https) by passing a url instead of a local path.
In [2]:
Copied!
from kloppy import statsbomb
dataset = statsbomb.load(
event_data="https://raw.githubusercontent.com/statsbomb/open-data/master/data/events/15946.json",
lineup_data="https://raw.githubusercontent.com/statsbomb/open-data/master/data/lineups/15946.json",
# Optional arguments
coordinates="statsbomb",
event_types=["pass", "shot"]
)
dataset.to_df().head()
from kloppy import statsbomb
dataset = statsbomb.load(
event_data="https://raw.githubusercontent.com/statsbomb/open-data/master/data/events/15946.json",
lineup_data="https://raw.githubusercontent.com/statsbomb/open-data/master/data/lineups/15946.json",
# Optional arguments
coordinates="statsbomb",
event_types=["pass", "shot"]
)
dataset.to_df().head()
Out[2]:
event_id | event_type | result | success | period_id | timestamp | end_timestamp | ball_state | ball_owning_team | team_id | player_id | coordinates_x | coordinates_y | end_coordinates_x | end_coordinates_y | receiver_player_id | set_piece_type | body_part_type | pass_type | |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
0 | 34208ade-2af4-45c3-970e-655937cad938 | PASS | COMPLETE | True | 1 | 0.098 | 2.007 | alive | 206 | 206 | 6581 | 60.5 | 40.5 | 35.5 | 25.5 | 6855 | KICK_OFF | LEFT_FOOT | NaN |
1 | d1cccb73-c7ef-4b02-8267-ebd7f149904b | PASS | INCOMPLETE | False | 1 | 3.497 | 6.785 | alive | 206 | 206 | 6855 | 35.5 | 28.5 | 85.5 | 72.5 | None | NaN | RIGHT_FOOT | LONG_BALL |
2 | f1cc47d6-4b19-45a6-beb9-33d67fc83f4b | PASS | COMPLETE | True | 1 | 6.785 | 8.431 | alive | 217 | 217 | 5203 | 34.5 | 7.5 | 34.5 | 20.5 | 5470 | NaN | HEAD | HEAD_PASS |
3 | f774571f-4b65-43a0-9bfc-6384948d1b82 | PASS | COMPLETE | True | 1 | 8.431 | 9.576 | alive | 217 | 217 | 5470 | 35.5 | 20.5 | 35.5 | 1.5 | 5477 | NaN | HEAD | HEAD_PASS |
4 | 46f0e871-3e72-4817-9a53-af27583ba6c1 | PASS | COMPLETE | True | 1 | 10.433 | 11.150 | alive | 217 | 217 | 5477 | 33.5 | 2.5 | 25.5 | 1.5 | 5211 | NaN | RIGHT_FOOT | NaN |
Load open data¶
For loading Statsbomb open data you can also use statsbomb.load_open_data
. The api is very simular but you don't have to pass the urls.
In [3]:
Copied!
from kloppy import statsbomb
dataset = statsbomb.load_open_data(
match_id=15946,
# Optional arguments
coordinates="statsbomb",
event_types=["pass", "shot"]
)
dataset.to_df().head()
from kloppy import statsbomb
dataset = statsbomb.load_open_data(
match_id=15946,
# Optional arguments
coordinates="statsbomb",
event_types=["pass", "shot"]
)
dataset.to_df().head()
/Users/koen/Developer/Projects/PySport/kloppy/.venv/lib/python3.10/site-packages/kloppy-3.7.1-py3.10.egg/kloppy/_providers/statsbomb.py:67: UserWarning: You are about to use StatsBomb public data. By using this data, you are agreeing to the user agreement. The user agreement can be found here: https://github.com/statsbomb/open-data/blob/master/LICENSE.pdf warnings.warn(
Out[3]:
event_id | event_type | result | success | period_id | timestamp | end_timestamp | ball_state | ball_owning_team | team_id | player_id | coordinates_x | coordinates_y | end_coordinates_x | end_coordinates_y | receiver_player_id | set_piece_type | body_part_type | pass_type | |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
0 | 34208ade-2af4-45c3-970e-655937cad938 | PASS | COMPLETE | True | 1 | 0.098 | 2.007 | alive | 206 | 206 | 6581 | 60.5 | 40.5 | 35.5 | 25.5 | 6855 | KICK_OFF | LEFT_FOOT | NaN |
1 | d1cccb73-c7ef-4b02-8267-ebd7f149904b | PASS | INCOMPLETE | False | 1 | 3.497 | 6.785 | alive | 206 | 206 | 6855 | 35.5 | 28.5 | 85.5 | 72.5 | None | NaN | RIGHT_FOOT | LONG_BALL |
2 | f1cc47d6-4b19-45a6-beb9-33d67fc83f4b | PASS | COMPLETE | True | 1 | 6.785 | 8.431 | alive | 217 | 217 | 5203 | 34.5 | 7.5 | 34.5 | 20.5 | 5470 | NaN | HEAD | HEAD_PASS |
3 | f774571f-4b65-43a0-9bfc-6384948d1b82 | PASS | COMPLETE | True | 1 | 8.431 | 9.576 | alive | 217 | 217 | 5470 | 35.5 | 20.5 | 35.5 | 1.5 | 5477 | NaN | HEAD | HEAD_PASS |
4 | 46f0e871-3e72-4817-9a53-af27583ba6c1 | PASS | COMPLETE | True | 1 | 10.433 | 11.150 | alive | 217 | 217 | 5477 | 33.5 | 2.5 | 25.5 | 1.5 | 5211 | NaN | RIGHT_FOOT | NaN |