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.
Specify a default value for when conditions in when() are not met.
Syntax
otherwise(value)
Parameters
| Parameter | Type | Description |
|---|---|---|
value |
value | Default value to return |
Returns
Column
Examples
from pyspark.sql import functions as sf
df = spark.createDataFrame(
[(2, "Alice"), (5, "Bob")], ["age", "name"])
df.select(df.name, sf.when(df.age > 3, 1).otherwise(0)).show()
# +-----+-------------------------------------+
# | name|CASE WHEN (age > 3) THEN 1 ELSE 0 END|
# +-----+-------------------------------------+
# |Alice| 0|
# | Bob| 1|
# +-----+-------------------------------------+