pyspark.sql.functions.struct#
- pyspark.sql.functions.struct(*cols)[source]#
Creates a new struct column.
New in version 1.4.0.
Changed in version 3.4.0: Supports Spark Connect.
- Parameters
- Returns
Column
a struct type column of given columns.
See also
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}| +-----+---+-----------------+