pyspark.sql.functions.named_struct#
- pyspark.sql.functions.named_struct(*cols)[source]#
Creates a struct with the given field names and values.
New in version 3.5.0.
See also
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}| +---+---+------------------------+