polars.DataFrame.apply#

DataFrame.apply(
function: Callable[[tuple[Any, ...]], Any],
return_dtype: PolarsDataType | None = None,
*,
inference_size: int = 256,
) DataFrame[source]#

Apply a custom/user-defined function (UDF) over the rows of the DataFrame.

Deprecated since version 0.19.0: This method has been renamed to DataFrame.map_rows().

Parameters:
function

Custom function or lambda.

return_dtype

Output type of the operation. If none given, Polars tries to infer the type.

inference_size

Only used in the case when the custom function returns rows. This uses the first n rows to determine the output schema