omfpandas.utils.pandas_utils.aggregate

omfpandas.utils.pandas_utils.aggregate(df, agg_dict, cat_treatment='majority', proportions_as_columns=False)[source]

Aggregate a DataFrame using a provided dictionary.

Parameters:
  • df (DataFrame) – The DataFrame to aggregate.

  • agg_dict (dict) – A dictionary where keys are the columns to be aggregated and values are the weight columns.

  • cat_treatment (Literal['majority', 'proportions']) – A string indicating how to treat categorical columns. ‘majority’ returns the majority category, ‘proportions’ returns the proportions of each category.

  • proportions_as_columns (bool) – A boolean indicating whether to return category proportions as separate columns.

Returns:

The aggregated DataFrame with columns in the same order as the incoming DataFrame.

Return type:

pd.DataFrame