pyspark.sql.functions.zeroifnull#

pyspark.sql.functions.zeroifnull(col)[source]#

Returns zero if col is null, or col otherwise.

New in version 4.0.0.

Parameters
colColumn or column name

Examples

>>> import pyspark.sql.functions as sf
>>> df = spark.createDataFrame([(None,), (1,)], ["a"])
>>> df.select('*', sf.zeroifnull(df.a)).show()
+----+-------------+
|   a|zeroifnull(a)|
+----+-------------+
|NULL|            0|
|   1|            1|
+----+-------------+
>>> df.select('*', sf.zeroifnull('a')).show()
+----+-------------+
|   a|zeroifnull(a)|
+----+-------------+
|NULL|            0|
|   1|            1|
+----+-------------+