zeroifnull
Returns zero if col is null, or col otherwise.
For the corresponding Databricks SQL function, see zeroifnull function.
Syntax
Python
from pyspark.databricks.sql import functions as dbf
dbf.zeroifnull(col=<col>)
Parameters
Parameter | Type | Description |
|---|---|---|
|
| The column to check. |
Examples
Python
from pyspark.databricks.sql import functions as dbf
df = spark.createDataFrame([(None,), (1,)], ["a"])
df.select('*', dbf.zeroifnull(df.a)).show()
Output
+----+-------------+
| a|zeroifnull(a)|
+----+-------------+
|NULL| 0|
| 1| 1|
+----+-------------+