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

# Unstack (Long to Wide)

> Pivot a long-format dataset to wide format, turning the values of an entity column into columns of their own.

Sooner or later you find the data you need, but not in the shape you need it — values that should be columns are rows, or the other way round. Transposing doesn't fix it, because the entity columns have to be preserved. **Unstack** and [Melt](/steps/melt-dataset) do.

<Frame>
  <img src="https://mintcdn.com/alphacastio/ttF_U-V9HDrmrPbo/images/steps/reshape-long-wide.png?fit=max&auto=format&n=ttF_U-V9HDrmrPbo&q=85&s=3f2a5232922b162dd491fee642323613" alt="Diagram showing long format and wide format side by side" width="329" height="374" data-path="images/steps/reshape-long-wide.png" />
</Frame>

**Unstack** goes from long to wide: the values of an entity column become new columns.

## Example

<Steps>
  <Step title="Load long-format data">
    Start with some Yahoo Finance data. The tickers (Apple, Microsoft, Google and so on) are values inside a single `Ticker` column. Suppose you need them side by side as columns, and only want the closing price rather than open-high-low-close.

    <Frame>
      <img src="https://mintcdn.com/alphacastio/ttF_U-V9HDrmrPbo/images/steps/unstack-dataset-2.png?fit=max&auto=format&n=ttF_U-V9HDrmrPbo&q=85&s=ce90e1a63e4671df682599a3c183e542" alt="Yahoo Finance data in long format, tickers as row values" width="3280" height="1047" data-path="images/steps/unstack-dataset-2.png" />
    </Frame>
  </Step>

  <Step title="Add the Long to Wide (Unstack) step">
    <Frame>
      <img src="https://mintcdn.com/alphacastio/ttF_U-V9HDrmrPbo/images/steps/unstack-dataset-3.png?fit=max&auto=format&n=ttF_U-V9HDrmrPbo&q=85&s=f9b2ad717eb41d616e78183bca364080" alt="Configuring the Long to Wide step" width="2507" height="1051" data-path="images/steps/unstack-dataset-3.png" />
    </Frame>
  </Step>

  <Step title="Review the result">
    Each ticker now has its own column.

    <Frame>
      <img src="https://mintcdn.com/alphacastio/ttF_U-V9HDrmrPbo/images/steps/unstack-result.png?fit=max&auto=format&n=ttF_U-V9HDrmrPbo&q=85&s=92349f96466953a8d376292d3d9a0a04" alt="The resulting wide-format dataset" width="2326" height="543" data-path="images/steps/unstack-result.png" />
    </Frame>
  </Step>
</Steps>

<Tip>
  See the [example pipeline](https://www.alphacast.io/pipelines/2022-6-10-UYhLlh/view) for both directions in one place.
</Tip>

## Reversing it

To go back the other way, use [Melt (Wide to Long)](/steps/melt-dataset).

## Next steps

<CardGroup cols={2}>
  <Card title="Melt (Wide to Long)" icon="arrows-left-right" href="/steps/melt-dataset">
    The inverse operation.
  </Card>

  <Card title="Merge branches" icon="code-merge" href="/steps/merge">
    Join the reshaped data with another dataset.
  </Card>
</CardGroup>
