socceraction.data.opta.OptaLoader

class socceraction.data.opta.OptaLoader(root, parser='xml', feeds=None)

Load Opta data feeds from a local folder.

Parameters:
  • root (str) – Root-path of the data.

  • parser (str or dict) –

    Either ‘xml’, ‘json’, ‘statsperform’, ‘whoscored’ or a dict with a custom parser for each feed. The default xml parser supports F7 and F24 feeds; the default json parser supports F1, F9 and F24 feeds, the StatsPerform parser supports MA1 and MA3 feeds. Custom parsers can be specified as:

    {
        'feed1_name': Feed1Parser
        'feed2_name': Feed2Parser
    }
    

    where Feed1Parser and Feed2Parser are classes implementing OptaParser and ‘feed1_name’ and ‘feed2_name’ are a unique ID for each feed that matches to the keys in feeds.

  • feeds (dict) –

    Glob pattern describing from which files the data from a specific game can be retrieved. For example, if files are named:

    f7-1-2021-17362.xml
    f24-1-2021-17362.xml
    

    use:

    feeds = {
        'f7': "f7-{competition_id}-{season_id}-{game_id}.xml",
        'f24': "f24-{competition_id}-{season_id}-{game_id}.xml"
    }
    

Raises:

ValueError – If an invalid parser is provided.

Methods

__init__

competitions

Return a dataframe with all available competitions and seasons.

events

Return a dataframe with the event stream of a game.

games

Return a dataframe with all available games in a season.

players

Return a dataframe with all players that participated in a game.

teams

Return a dataframe with both teams that participated in a game.