MultiGroupBy#
- class mobgap.utils.df_operations.MultiGroupBy(
- primary_df: DataFrame,
- secondary_dfs: DataFrame | list[DataFrame],
- groupby: str | list[str],
- **kwargs: Unpack[dict[str, Any]],
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_groupbyfor the creation of this object.- Attributes:
groupsA dictionary with the group names as keys and the group dataframes as values.
ngroupsThe number of groups.
primary_groupbyThe primary groupby object.
secondary_groupbysThe 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]],
- apply( ) 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( ) 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 primary_groupby: DataFrameGroupBy#
The primary groupby object.
This is the grouper created from the primary dataframe.