pyspark.sql.functions.map_from_entries

pyspark.sql.functions.map_from_entries(col: ColumnOrName) → pyspark.sql.column.Column[source]

Collection function: Returns a map created from the given array of entries.

New in version 2.4.0.

Parameters
colColumn or str

name of column or expression

Examples

>>> from pyspark.sql.functions import map_from_entries
>>> df = spark.sql("SELECT array(struct(1, 'a'), struct(2, 'b')) as data")
>>> df.select(map_from_entries("data").alias("map")).show()
+----------------+
|             map|
+----------------+
|{1 -> a, 2 -> b}|
+----------------+