Kopīgot, izmantojot


struct

Creates a new struct column.

Syntax

from pyspark.sql import functions as sf

sf.struct(*cols)

Parameters

Parameter Type Description
cols list, set, pyspark.sql.Column or column name Column names or Columns to contain in the output struct.

Returns

pyspark.sql.Column: a struct type column of given columns.

Examples

import pyspark.sql.functions as sf
df = spark.createDataFrame([("Alice", 2), ("Bob", 5)], ("name", "age"))
df.select("*", sf.struct('age', df.name)).show()
+-----+---+-----------------+
| name|age|struct(age, name)|
+-----+---+-----------------+
|Alice|  2|       {2, Alice}|
|  Bob|  5|         {5, Bob}|
+-----+---+-----------------+