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.
Creates a struct with the given field names and values.
Syntax
from pyspark.sql import functions as sf
sf.named_struct(*cols)
Parameters
| Parameter | Type | Description |
|---|---|---|
cols |
pyspark.sql.Column or column name |
List of columns to work on. |
Returns
pyspark.sql.Column:
Examples
import pyspark.sql.functions as sf
df = spark.createDataFrame([(1, 2)], ['a', 'b'])
df.select("*", sf.named_struct(sf.lit('x'), df.a, sf.lit('y'), "b")).show()
+---+---+------------------------+
| a| b|named_struct(x, a, y, b)|
+---+---+------------------------+
| 1| 2| {1, 2}|
+---+---+------------------------+