MultiGroupBy#

class mobgap.utils.df_operations.MultiGroupBy(
primary_df: DataFrame,
secondary_dfs: DataFrame | list[DataFrame],
groupby: str | list[str],
**kwargs: Unpack[dict[str, Any]],
)[source]#

Object representing the grouping result of multiple dataframes.

This is used as proxy object to replicate an API similar to the normal pandas groupy object, but allowing to group multiple dataframes by the same index levels to apply a function to each group across all dataframes.

See create_multi_groupby for the creation of this object.

Attributes:
groups

A dictionary with the group names as keys and the group dataframes as values.

ngroups

The number of groups.

primary_groupby

The primary groupby object.

secondary_groupbys

The secondary groupby objects.

Methods

apply(func, *args, **kwargs)

Apply a function that takes the group values from each df as input.

get_group(name)

Get an individual group by name.

__init__(
primary_df: DataFrame,
secondary_dfs: DataFrame | list[DataFrame],
groupby: str | list[str],
**kwargs: Unpack[dict[str, Any]],
) None[source]#
apply(
func: Callable,
*args: Unpack[list[Any]],
**kwargs: Unpack[dict[str, Any]],
) DataFrame[source]#

Apply a function that takes the group values from each df as input.

The function is expected to take n dataframes as input, where n is the number of secondary dataframes + 1. The expected signature is: func(group_df_prim, group_df_sec_0, group_df_sec_1, ..., *args, **kwargs)

get_group(
name: str | tuple[str, ...],
) tuple[DataFrame, ...][source]#

Get an individual group by name.

Returns:
A tuple containing the groups from each dataframe.
property groups: dict[str | tuple[str, ...], tuple[DataFrame, ...]]#

A dictionary with the group names as keys and the group dataframes as values.

property ngroups: int#

The number of groups.

property primary_groupby: DataFrameGroupBy#

The primary groupby object.

This is the grouper created from the primary dataframe.

property secondary_groupbys: list[DataFrameGroupBy]#

The secondary groupby objects.

These are the groupers created from the secondary dataframes.

Examples using mobgap.utils.df_operations.MultiGroupBy#

Evaluation of final walking bout level DMOs

Evaluation of final walking bout level DMOs

ICD Evaluation

ICD Evaluation