> ## Documentation Index
> Fetch the complete documentation index at: https://knowledge.cloudquant.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Melt and Wide to Long - Unpivoting a Pivot

> Convert DataFrames from wide to long format using pandas melt and wide_to_long methods.

# Melt and wide to long - unpivoting a pivot

Pandas provides two methods for converting DataFrames from wide to long format (unpivoting).

## Melt method

Unpivot a DataFrame from wide to long format, optionally leaving identifiers set.

```python theme={null}
df.melt()
```

The `melt` function provides flexibility when restructuring data from a wide format into a long format. You can specify which columns serve as identifiers and which become variable-value pairs.

<Tip>
  Use `melt` when you need fine-grained control over which columns become identifiers and which become variable-value pairs.
</Tip>

**Documentation:** [pandas.melt](https://pandas.pydata.org/docs/reference/api/pandas.melt.html)

## Wide to long method

Unpivot a DataFrame from wide to long format. Less flexible but more user-friendly than melt.

```python theme={null}
pd.wide_to_long()
```

The `wide_to_long` function offers a more accessible alternative to melt, trading some flexibility for improved usability when performing standard unpivoting operations.

<Tip>
  Use `wide_to_long` for simpler, standard unpivoting operations where ease of use is more important than flexibility.
</Tip>

**Documentation:** [pandas.wide\_to\_long](https://pandas.pydata.org/docs/reference/api/pandas.wide_to_long.html)
