struct
Creates a new struct column.
Syntax
Python
from pyspark.sql import functions as sf
sf.struct(*cols)
Parameters
Parameter | Type | Description |
|---|---|---|
| list, set, | Column names or Columns to contain in the output struct. |
Returns
pyspark.sql.Column: a struct type column of given columns.
Examples
Python
import pyspark.sql.functions as sf
df = spark.createDataFrame([("Alice", 2), ("Bob", 5)], ("name", "age"))
df.select("*", sf.struct('age', df.name)).show()
Output
+-----+---+-----------------+
| name|age|struct(age, name)|
+-----+---+-----------------+
|Alice| 2| {2, Alice}|
| Bob| 5| {5, Bob}|
+-----+---+-----------------+