---
title: melt
description: "DataFrame.melt method in PySpark: Unpivot a DataFrame from wide format to long format, optionally leaving identifier columns set."
canonical_url: https://docs.databricks.com/aws/en/pyspark/reference/classes/dataframe/melt
---

# melt

Unpivot a DataFrame from wide format to long format, optionally leaving identifier columns set. This is the reverse to `groupBy(...).pivot(...).agg(...)`, except for the aggregation, which cannot be reversed.

`melt` is an alias for `unpivot`.

## Syntax

```
melt(ids: Union["ColumnOrName", List["ColumnOrName"], Tuple["ColumnOrName", ...]], values: Optional[Union["ColumnOrName", List["ColumnOrName"], Tuple["ColumnOrName", ...]]], variableColumnName: str, valueColumnName: str)
```

## Parameters

| Parameter            | Type                               | Description                                                                                                                                                                 |
| -------------------- | ---------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `ids`                | str, Column, tuple, list, optional | Column(s) to use as identifiers. Can be a single column or column name, or a list or tuple for multiple columns.                                                            |
| `values`             | str, Column, tuple, list, optional | Column(s) to unpivot. Can be a single column or column name, or a list or tuple for multiple columns. If not specified or empty, use all columns that are not set as `ids`. |
| `variableColumnName` | str                                | Name of the variable column.                                                                                                                                                |
| `valueColumnName`    | str                                | Name of the value column.                                                                                                                                                   |

## Returns

`DataFrame`: Unpivoted DataFrame.

## Notes

Supports Spark Connect.
