dilimap.utils.groupby

dilimap.utils.groupby(data, key, aggfunc='mean')

Groups a dataset by a specified key, preserving one-to-one categorical mappings.

  • Columns with a single unique value per group are retained as-is.

  • Columns with multiple unique values are aggregated using aggfunc.

  • Non-numeric categorical columns are retained only if they have a one-to-one mapping with key.

Parameters:
  • data (pandas.DataFrame or anndata.AnnData) – Input dataset. If AnnData, uses obs.

  • key (str) – The column name to group the data by.

  • aggfunc (str or function) – Aggregation function to apply to numerical columns.

Returns:

Grouped data.

Return type:

pandas.DataFrame