pyspark.sql.functions.ifnull#

pyspark.sql.functions.ifnull(col1, col2)[source]#

Returns col2 if col1 is null, or col1 otherwise.

New in version 3.5.0.

Parameters
col1Column or str
col2Column or str

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|
+------------+