daft.expressions.Expression.if_else#

Expression.if_else(if_true: daft.expressions.Expression, if_false: daft.expressions.Expression) daft.expressions.Expression[source]#

Conditionally choose values between two expressions using the current LOGICAL expression as a condition

Example

>>> # x = [2, 2, 2]
>>> # y = [1, 2, 3]
>>> # a = ["a", "a", "a"]
>>> # b = ["b", "b", "b"]
>>> # if_else_result = ["a", "b", "b"]
>>> (col("x") > col("y")).if_else(col("a"), col("b"))
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 and if_false.

Return type

Expression