pyspark.sql.tvf.TableValuedFunction.posexplode#
- TableValuedFunction.posexplode(collection)[source]#
Returns a
DataFrame
containing a new row for each element with position in the given array or map. Uses the default column name pos for position, and col for elements in the array and key and value for elements in the map unless specified otherwise.New in version 4.0.0.
- Parameters
- collection
Column
target column to work on.
- collection
- Returns
DataFrame
See also
Examples
>>> import pyspark.sql.functions as sf >>> spark.tvf.posexplode(sf.array(sf.lit(1), sf.lit(2), sf.lit(3))).show() +---+---+ |pos|col| +---+---+ | 0| 1| | 1| 2| | 2| 3| +---+---+ >>> spark.tvf.posexplode(sf.create_map(sf.lit("a"), sf.lit("b"))).show() +---+---+-----+ |pos|key|value| +---+---+-----+ | 0| a| b| +---+---+-----+