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.

Parameters
colsColumn or str

list of columns to work on.

Returns
Column

Examples

>>> df = spark.createDataFrame([(1, 2, 3)], ['a', 'b', 'c'])
>>> df.select(named_struct(lit('x'), df.a, lit('y'), df.b).alias('r')).collect()
[Row(r=Row(x=1, y=2))]