pyspark.sql.functions.map_from_arrays

pyspark.sql.functions.map_from_arrays(col1, col2)[source]

Creates a new map from two arrays.

Parameters
  • col1 – name of column containing a set of keys. All elements should not be null

  • col2 – name of column containing a set of values

>>> df = spark.createDataFrame([([2, 5], ['a', 'b'])], ['k', 'v'])
>>> df.select(map_from_arrays(df.k, df.v).alias("map")).show()
+----------------+
|             map|
+----------------+
|[2 -> a, 5 -> b]|
+----------------+

New in version 2.4.