pyspark.sql.functions.
map_from_arrays
Creates a new map from two arrays.
New in version 2.4.0.
Changed in version 3.4.0: Supports Spark Connect.
Column
name of column containing a set of keys. All elements should not be null
name of column containing a set of values
a column of map type.
Examples
>>> df = spark.createDataFrame([([2, 5], ['a', 'b'])], ['k', 'v']) >>> df = df.select(map_from_arrays(df.k, df.v).alias("col")) >>> df.show() +----------------+ | col| +----------------+ |{2 -> a, 5 -> b}| +----------------+ >>> df.printSchema() root |-- col: map (nullable = true) | |-- key: long | |-- value: string (valueContainsNull = true)