# xarray.DataArray.unstack

#### DataArray.unstack(dim=None, \*, fill_value=<NA>, sparse=False)[[source]](https://github.com/pydata/xarray/blob/v2026.09.0/xarray/core/dataarray.py#L3126-L3188)

Unstack existing dimensions corresponding to MultiIndexes into
multiple new dimensions.

New dimensions will be added at the end.

* **Parameters:**
  * **dim** ([`str`](xarray.DataArray.str.html.md#xarray.DataArray.str), `Iterable` of `Hashable` or [`None`](https://docs.python.org/3/builtins/constants.html#None), *optional*) – Dimension(s) over which to unstack. By default unstacks all
    MultiIndexes.
  * **fill_value** ([scalar](../user-guide/terminology.html.md#term-scalar) or [dict-like](https://docs.python.org/3/glossary.html#term-mapping), *default*: `nan`) – Value to be filled. If a dict-like, maps variable names to
    fill values. Use the data array’s name to refer to its
    name. If not provided or if the dict-like does not contain
    all variables, the dtype’s NA value will be used.
  * **sparse** ([`bool`](https://docs.python.org/3/builtins/functions.html#bool), *default*: [`False`](https://docs.python.org/3/builtins/constants.html#False)) – Use sparse-array if True
* **Returns:**
  **unstacked** ([`DataArray`](xarray.DataArray.html.md#xarray.DataArray)) – Array with unstacked data.

### Examples

<div class="try_examples_button_container"><button class="try_examples_button" onclick="window.tryExamplesShowIframe('4e567de7-0241-40ea-b17d-817be234b22f','50b11822-9ce2-42a5-b283-801f73e23e97','c0897eee-80d4-4d17-8198-991d00491f27','../lite/tree/../notebooks/index.html?path=d7be506f_c5c8_4998_a126_4e54d2e373c6.ipynb','None')">Try it in your browser!</button></div>
```pycon
>>> arr = xr.DataArray(
...     np.arange(6).reshape(2, 3),
...     coords=[("x", ["a", "b"]), ("y", [0, 1, 2])],
... )
>>> arr
<xarray.DataArray (x: 2, y: 3)> Size: 48B
array([[0, 1, 2],
       [3, 4, 5]])
Coordinates:
  * x        (x) <U1 8B 'a' 'b'
  * y        (y) int64 24B 0 1 2
>>> stacked = arr.stack(z=("x", "y"))
>>> stacked.indexes["z"]
MultiIndex([('a', 0),
            ('a', 1),
            ('a', 2),
            ('b', 0),
            ('b', 1),
            ('b', 2)],
           name='z')
>>> roundtripped = stacked.unstack()
>>> arr.identical(roundtripped)
True
```

<div id="c0897eee-80d4-4d17-8198-991d00491f27" class="try_examples_outer_iframe  hidden"><div class="try_examples_button_container"><button class="try_examples_button" onclick="window.tryExamplesHideIframe('4e567de7-0241-40ea-b17d-817be234b22f','c0897eee-80d4-4d17-8198-991d00491f27')">Go Back</button><button class="try_examples_button" onclick="window.openInNewTab('4e567de7-0241-40ea-b17d-817be234b22f','c0897eee-80d4-4d17-8198-991d00491f27')">Open In Tab</button></div><div id="50b11822-9ce2-42a5-b283-801f73e23e97" class="jupyterlite_sphinx_iframe_container"></div></div><script>document.addEventListener("DOMContentLoaded", function() {window.loadTryExamplesConfig("../try_examples.json");});</script>

#### SEE ALSO
[`DataArray.stack`](xarray.DataArray.stack.html.md#xarray.DataArray.stack)
