daft.expressions.Expression.apply
daft.expressions.Expression.apply#
- Expression.apply(func: Callable, return_dtype: Optional[daft.types.ExpressionType] = None, return_type: Optional[Any] = None) daft.expressions.Expression [source]#
Apply a function on a given expression
Example
>>> def f(x_val: str) -> int: >>> return int(x_val) if x_val.isnumeric() else 0 >>> >>> col("x").apply(f, return_dtype=int)
- Parameters
func (Callable) – Function to run per value of the expression
return_dtype (Optional[Type], optional) – Return type of the function that was ran. This defaults to None which assumes the return type to be an arbitrary Python object.
- Returns
New expression after having run the function on the expression
- Return type