Column.
otherwise
Evaluates a list of conditions and returns one of multiple possible result expressions. If Column.otherwise() is not invoked, None is returned for unmatched conditions.
Column.otherwise()
New in version 1.4.0.
Changed in version 3.4.0: Supports Spark Connect.
a literal value, or a Column expression.
Column
Column representing whether each element of Column is unmatched conditions.
See also
pyspark.sql.functions.when
Examples
>>> from pyspark.sql import functions as F >>> df = spark.createDataFrame( ... [(2, "Alice"), (5, "Bob")], ["age", "name"]) >>> df.select(df.name, F.when(df.age > 3, 1).otherwise(0)).show() +-----+-------------------------------------+ | name|CASE WHEN (age > 3) THEN 1 ELSE 0 END| +-----+-------------------------------------+ |Alice| 0| | Bob| 1| +-----+-------------------------------------+