---
title: TableValuedFunction.posexplode
description: "TableValuedFunction.posexplode function in PySpark: Returns a DataFrame containing a new row for each element with position in the given array or map."
canonical_url: https://docs.databricks.com/aws/en/pyspark/reference/functions/tvf-posexplode
---

# TableValuedFunction.posexplode

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.

## Syntax

```python
spark.tvf.posexplode(collection)
```

## Parameters

| Parameter    | Type                 | Description               |
| ------------ | -------------------- | ------------------------- |
| `collection` | `pyspark.sql.Column` | Target column to work on. |

## Returns

`pyspark.sql.DataFrame`: A DataFrame with a new row for each element along with its position.

## Examples

```python
import pyspark.sql.functions as sf
spark.tvf.posexplode(sf.array(sf.lit(1), sf.lit(2), sf.lit(3))).show()
```

```Output
+---+---+
|pos|col|
+---+---+
|  0|  1|
|  1|  2|
|  2|  3|
+---+---+
```

```python
import pyspark.sql.functions as sf
spark.tvf.posexplode(sf.create_map(sf.lit("a"), sf.lit("b"))).show()
```

```Output
+---+---+-----+
|pos|key|value|
+---+---+-----+
|  0|  a|    b|
+---+---+-----+
```
