sportslabkit.dataframe.base#

Overview#

Classes#

BaseSLKDataFrame

-

Classes#

class sportslabkit.dataframe.base.BaseSLKDataFrame[source]#

Bases: pandas.DataFrame

Overview

Methods#

save_dataframe(path_or_buf)

Save a dataframe to a file.

get_data(frame, playerid, teamid, attributes)

Get specific data from the dataframe.

iter_frames(apply_func)

Iterate over the frames of the dataframe.

iter_players(apply_func, drop)

Iterate over the players of the dataframe.

iter_teams(apply_func, drop)

Iterate over the teams of the dataframe.

iter_attributes(apply_func, drop)

Iterate over the attributes of the dataframe.

to_long_df(level, dropna)

Convert a dataframe to a long format.

is_long_format()

Check if the dataframe is in long format.

get_frame(frame)

Get a specific frame from the dataframe.

Members

save_dataframe(path_or_buf: FilePath | WriteBuffer[bytes] | WriteBuffer[str]) None[source]#

Save a dataframe to a file.

Parameters:
  • df (pd.DataFrame) – Dataframe to save.

  • path_or_buf (FilePath | WriteBuffer[bytes] | WriteBuffer[str]) – Path to save the dataframe.

get_data(frame=None, playerid=None, teamid=None, attributes=None)[source]#

Get specific data from the dataframe.

Parameters:
  • frame (int or list of int, optional) – Frame(s) to get.

  • player (int or list of int, optional) – Player ID(s) to get.

  • team (int or list of int, optional) – Team ID(s) to get.

  • attributes (str or list of str, optional) – Attribute(s) to get.

Returns:

Dataframe with the selected data.

Return type:

pd.DataFrame

iter_frames(apply_func=None)[source]#

Iterate over the frames of the dataframe.

Parameters:

apply_func (function, optional) – Function to apply to each group. Defaults to None.

iter_players(apply_func=None, drop=True)[source]#

Iterate over the players of the dataframe.

Parameters:
  • apply_func (function, optional) – Function to apply to each group. Defaults to None.

  • drop (bool, optional) – Drop the level of the dataframe. Defaults to True.

iter_teams(apply_func=None, drop=True)[source]#

Iterate over the teams of the dataframe.

Parameters:
  • apply_func (function, optional) – Function to apply to each group. Defaults to None.

  • drop (bool, optional) – Drop the level of the dataframe. Defaults to True.

iter_attributes(apply_func=None, drop=True)[source]#

Iterate over the attributes of the dataframe.

Parameters:
  • apply_func (function, optional) – Function to apply to each group. Defaults to None.

  • drop (bool, optional) – Drop the level of the dataframe. Defaults to True.

to_long_df(level='Attributes', dropna=True)[source]#

Convert a dataframe to a long format.

Parameters:
  • df (pd.DataFrame) – Dataframe to convert.

  • level (str, optional) – Level to convert to long format. Defaults to ‘Attributes’. Options are ‘Attributes’, ‘TeamID’, ‘PlayerID’.

Returns:

Dataframe in long format.

Return type:

pd.DataFrame

is_long_format()[source]#

Check if the dataframe is in long format.

Returns:

True if the dataframe is in long format, False otherwise.

Return type:

bool

get_frame(frame)[source]#

Get a specific frame from the dataframe.

Parameters:

frame (int) – Frame to get.

Returns:

Dataframe with the frame.

Return type:

pd.DataFrame