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
functo 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.
funcis called once per (group, column) pair with a single-column Series, not a whole-group DataFrame. Uselambda g: g - g.mean(), notg['col'] - g['col'].mean().If
funcis a class, it is instantiated once per group,__call__is invoked per (group, column), andclose()(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:
See also
groupby_applyApply a function to each group as a whole frame.
groupby_transform_chunkPer-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