Nota
Capaian ke halaman ini memerlukan kebenaran. Anda boleh cuba mendaftar masuk atau menukar direktori.
Capaian ke halaman ini memerlukan kebenaran. Anda boleh cuba menukar direktori.
Returns col2 if col1 is not null, or col3 otherwise.
For the corresponding Databricks SQL function, see nvl2 function.
Syntax
from pyspark.sql import functions as dbf
dbf.nvl2(col1=<col1>, col2=<col2>, col3=<col3>)
Parameters
| Parameter | Type | Description |
|---|---|---|
col1 |
pyspark.sql.Column or str |
The column to check. |
col2 |
pyspark.sql.Column or str |
The value to return if col1 is not null. |
col3 |
pyspark.sql.Column or str |
The value to return if col1 is null. |
Examples
from pyspark.sql import functions as dbf
df = spark.createDataFrame([(None, 8, 6,), (1, 9, 9,)], ["a", "b", "c"])
df.select('*', dbf.nvl2(df.a, df.b, df.c)).show()
+----+---+---+-------------+
| a| b| c|nvl2(a, b, c)|
+----+---+---+-------------+
|NULL| 8| 6| 6|
| 1| 9| 9| 9|
+----+---+---+-------------+