Lưu ý
Cần có ủy quyền mới truy nhập được vào trang này. Bạn có thể thử đăng nhập hoặc thay đổi thư mục.
Cần có ủy quyền mới truy nhập được vào trang này. Bạn có thể thử thay đổi thư mục.
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|
+----+---+---+-------------+