socceraction.data.opta.OptaLoader#

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

Load Opta data from a local folder.

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

  • parser (str or dict) –

    Either ‘xml’, ‘json’, ‘statsperform’, ‘whoscored’ or your 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’ correspond to the keys in ‘feeds’.

  • feeds (dict) –

    Glob pattern for each feed that should be parsed. 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"
    }
    

    If you use JSON files obtained from WhoScored use:

    feeds = {
        'whoscored': "{competition_id}-{season_id}/{game_id}.json",
    }
    

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.