maxframe.liteframe.groupby.LiteFrameGroupBy.transform#

LiteFrameGroupBy.transform(func, *, dtypes=None, skip_infer=False, input_frame_type='pandas', args=(), **kwargs)#

GroupBy.transform() – per-group column transform.

Applies func to each group independently and returns a LiteFrame with the same row count as the input (transform semantics). The output row order follows reducer/hash-partition order and is not aligned with the input frame.

Parameters:
  • func (callable or callable class) –

    Function receiving a per-group column (Series) and returning a transformed column of the same length. func is called once per (group, column) pair with a single-column Series, not a whole-group DataFrame. Use lambda g: g - g.mean(), not g['col'] - g['col'].mean().

    If func is a class, it is instantiated once per group, __call__ is invoked per (group, column), and close() (if defined) is always called at the end of each group.

  • dtypes (dict or pd.Series, optional) – Expected output dtypes.

  • skip_infer (bool, default False) – If True, skip dtype inference.

  • input_frame_type ({"pandas", "polars"}, default "pandas") – Frame type passed to func.

  • args (tuple) – Extra positional arguments forwarded to func.

  • **kwargs – Extra keyword arguments forwarded to func.

Returns:

Lazy LiteFrame with the same row count as the input, where each value is the per-group transform result. Call .execute() to materialize.

Return type:

LiteFrame

See also

groupby_apply

Apply a function to each group as a whole frame.

groupby_transform_chunk

Per-group-chunk transform.

Examples

>>> import maxframe.liteframe as mlf
>>> lf = mlf.LiteFrame({'key': ['a', 'a', 'b', 'b'], 'val': [1, 2, 3, 4]})

Center each value by its group mean (row count preserved):

>>> result = lf.groupby('key').transform(lambda g: g - g.mean(),
...                                      dtypes={'val': float})
>>> result.execute()
   val
0 -0.5
1  0.5
2 -0.5
3  0.5