daft.Expression.if_else#
- Expression.if_else(if_true: Expression, if_false: Expression) Expression [source]#
Conditionally choose values between two expressions using the current boolean expression as a condition
Example
>>> import daft >>> df = daft.from_pydict({"A": [1, 2, 3], "B": [0, 2, 4]}) >>> df = df.with_column("A_if_bigger_else_B", (df["A"] > df["B"]).if_else(df["A"], df["B"]),) >>> df.collect() ╭───────┬───────┬────────────────────╮ │ A ┆ B ┆ A_if_bigger_else_B │ │ --- ┆ --- ┆ --- │ │ Int64 ┆ Int64 ┆ Int64 │ ╞═══════╪═══════╪════════════════════╡ │ 1 ┆ 0 ┆ 1 │ ├╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┤ │ 2 ┆ 2 ┆ 2 │ ├╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┤ │ 3 ┆ 4 ┆ 4 │ ╰───────┴───────┴────────────────────╯ (Showing first 3 of 3 rows)
- Parameters:
if_true (Expression) – Values to choose if condition is true
if_false (Expression) – Values to choose if condition is false
- Returns:
New expression where values are chosen from
if_true
andif_false
.- Return type:
Expression