pyspark.sql.functions.nullif

pyspark.sql.functions.nullif(col1: ColumnOrName, col2: ColumnOrName) → pyspark.sql.column.Column[source]

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

New in version 3.5.0.

Parameters
col1Column or str
col2Column or str

Examples

>>> df = spark.createDataFrame([(None, None,), (1, 9,)], ["a", "b"])
>>> df.select(nullif(df.a, df.b).alias('r')).collect()
[Row(r=None), Row(r=1)]