Skip to main content

nullif

Returns null if col1 equals to col2, or col1 otherwise.

For the corresponding Databricks SQL function, see nullif function.

Syntax​

Python
from pyspark.sql import functions as dbf

dbf.nullif(col1=<col1>, col2=<col2>)

Parameters​

Parameter

Type

Description

col1

pyspark.sql.Column or str

The first column to check.

col2

pyspark.sql.Column or str

The column to compare with col1.

Parameter

Type

Description

col1

pyspark.sql.Column or str

The first column to check.

col2

pyspark.sql.Column or str

The column to compare with col1.

Examples​

Python
from pyspark.sql import functions as dbf
df = spark.createDataFrame([(None, None,), (1, 9,)], ["a", "b"])
df.select('*', dbf.nullif(df.a, df.b)).show()
Output
+----+----+------------+
| a| b|nullif(a, b)|
+----+----+------------+
|NULL|NULL| NULL|
| 1| 9| 1|
+----+----+------------+