# xarray.DataArray.unstack

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

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('d96b5727-02a2-4c59-a4c0-31cb3fd620fc','d864092b-95e2-4355-945e-8701f34e442d','e5afded3-b8e4-4b31-b468-4cea7b7efa66','../lite/tree/../notebooks/index.html?path=d82846a4_999e_4000_bf06_173b47d72bb8.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="e5afded3-b8e4-4b31-b468-4cea7b7efa66" class="try_examples_outer_iframe  hidden"><div class="try_examples_button_container"><button class="try_examples_button" onclick="window.tryExamplesHideIframe('d96b5727-02a2-4c59-a4c0-31cb3fd620fc','e5afded3-b8e4-4b31-b468-4cea7b7efa66')">Go Back</button><button class="try_examples_button" onclick="window.openInNewTab('d96b5727-02a2-4c59-a4c0-31cb3fd620fc','e5afded3-b8e4-4b31-b468-4cea7b7efa66')">Open In Tab</button></div><div id="d864092b-95e2-4355-945e-8701f34e442d" 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)
