<jupyter_start><jupyter_text>Event dataOne of the main benfits of working with kloppy that it loads metadata with the event data. This metadata includes teams (name, ground and provider id) and players (name, jersey number, optional position and provider id). Using this metadata it becomes very easy to an analyse that is usable by humans, because it includes names instead of only numbers.This section shows how metadata is organized and some use-cases.  Loading statsbomb dataThe datasets module of kloppy makes it trivial to load statsbomb data. Keep in mind that by using the data you accept the license of the open-data project.<jupyter_code>from kloppy import datasets

dataset = datasets.load("statsbomb", options={"event_types": ["pass", "shot"]})<jupyter_output>/Users/koen/PycharmProjects/kloppy/.venv/lib/python3.7/site-packages/kloppy-1.0.0-py3.7.egg/kloppy/infra/datasets/event/statsbomb.py:12: 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

  "\n\nYou are about to use StatsBomb public data."<jupyter_text>Exploring metadatakloppy always loads the metadata for you and makes it available at the `metadata` property.<jupyter_code>metadata = dataset.metadata
home_team, away_team = metadata.teams<jupyter_output><empty_output><jupyter_text>After loading the data the metadata can be used to iterate over teams and players. By default `metadata.teams` contain `[HomeTeam, AwayTeam]`. `Team` and `Player` entities have the `__str__` magic method implemented to help you casting it to a string. When you want to<jupyter_code>print(f"{home_team.ground} - {home_team}")
print(f"{away_team.ground} - {away_team}")
[f"{player} ({player.jersey_no})" for player in home_team.players]

# get provider id for team
f"statsbomb team id: {home_team.team_id} - {away_team.team_id}"
# same for the players
[f"{player} id={player.player_id}" for player in metadata.teams[0].players]

# get player from first event
player = dataset.events[0].player
print(player)
print(player.team)
print(f"Teams are comparable? {player.team == away_team}")<jupyter_output><NAME>
Deportivo Alavés
Teams are comparable? True<jupyter_text>The `Team` and `Player` entities also contain the magic methods to use those a keys in dictionaries or use them in sets. This makes it easy to do some calculations, and show the results without mapping the player_id to a name.<jupyter_code>from collections import defaultdict

passes_per_player = defaultdict(list)
for event in dataset.events:
    if event.event_name == "pass":
        passes_per_player[event.player].append(event)
        
for player, passes in passes_per_player.items():
    print(f"{player} has {len(passes)} passes")<jupyter_output><NAME> has 14 passes
<NAME> has 18 passes
<NAME> has 79 passes
<NAME> has 138 passes
<NAME> has 65 passes
<NAME> has 121 passes
<NAME> has 11 passes
<NAME> has 23 passes
<NAME> has 79 passes
<NAME> has 31 passes
<NAME> has 85 passes
<NAME> has 63 passes
<NAME> has 92 passes
<NAME> has 25 passes
<NAME> has 35 passes
Mubarak Wakaso has 23 passes
<NAME> has 23 passes
<NAME> has 17 passes
<NAME> has 38 passes
<NAME> has 16 passes
<NAME> has 20 passes
<NAME> has 16 passes
<NAME> has 51 passes
<NAME> has 11 passes
<NAME> has 6 passes
<NAME> has 18 passes
<NAME>[...]<jupyter_text>Now let's filter on home_team.<jupyter_code>for player, passes in passes_per_player.items():
    if player.team == home_team:
        print(f"{player} has {len(passes)} passes")<jupyter_output><NAME> has 79 passes
<NAME> has 138 passes
<NAME> has 65 passes
<NAME> has 121 passes
<NAME> has 23 passes
<NAME> has 79 passes
<NAME> has 31 passes
<NAME> has 85 passes
<NAME> has 63 passes
<NAME> has 92 passes
<NAME> has 38 passes
<NAME> has 51 passes
<NAME> has 18 passes
<NAME> has 7 passes<jupyter_text>Use metadata when transforming to pandas dataframeThe metadata can also be used when transforming a dataset to a pandas dataframe. The `additional_columns` argument should be passed to `to_pandas`.<jupyter_code>from kloppy import to_pandas

dataframe = to_pandas(dataset, additional_columns={
    'player_name': lambda event: str(event.player),
    'team_name': lambda event: str(event.player.team)
})
dataframe[[
    'event_id', 'event_type', 'result', 'timestamp', 'player_id', 
    'player_name', 'team_name'
]].head()<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.09673815907059875, 'fraction_numerical': 0.020777479892761394, 'mean_word_length': 5.287921348314606, 'pattern_counts': {'":': 2, '<': 62, '<?xml version=': 0, '>': 62, 'https://': 1, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '6', 'dir': 'jupyter-structured-clean-dedup', 'id': '33115', 'license': 'BSD-3-Clause', 'n_tokens_mistral': 1497, 'n_tokens_neox': 1392, 'n_words': 540, 'path': 'docs/quickstart/event_data.ipynb', 'repo_name': 'FCrSTATS/kloppy', 'size': '5163'}