polars.apply

polars.apply(exprs: List[Union[str, polars.internals.expr.Expr]], f: Callable[[List[polars.internals.series.Series]], Union[polars.internals.series.Series, Any]], return_dtype: Optional[Type[polars.datatypes.DataType]] = None) polars.internals.expr.Expr

Apply a custom function in a GroupBy context.

Depending on the context it has the following behavior:

## Context

  • Select/Project

    Don’t do this, use map

  • GroupBy

    expected type f: Callable[[Series], Series] Applies a python function over each group.

Parameters
exprs

Input Series to f

f

Function to apply over the input

return_dtype

dtype of the output Series

Returns
Expr