pyspark.sql.functions.ifnull¶
-
pyspark.sql.functions.
ifnull
(col1: ColumnOrName, col2: ColumnOrName) → pyspark.sql.column.Column[source]¶ Returns col2 if col1 is null, or col1 otherwise.
New in version 3.5.0.
Examples
>>> import pyspark.sql.functions as sf >>> df = spark.createDataFrame([(None,), (1,)], ["e"]) >>> df.select(sf.ifnull(df.e, sf.lit(8))).show() +------------+ |ifnull(e, 8)| +------------+ | 8| | 1| +------------+