# 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('4bda29d2-ae98-4893-80a1-7e4c9cb08943','ff1f013f-988a-4981-8737-79002d4a5a3d','bf9e6581-4688-44ec-a9f3-6b0220b5a914','../lite/tree/../notebooks/index.html?path=6c177d5f_cc61_41d8_9488_a0ff6f3529c5.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="bf9e6581-4688-44ec-a9f3-6b0220b5a914" class="try_examples_outer_iframe  hidden"><div class="try_examples_button_container"><button class="try_examples_button" onclick="window.tryExamplesHideIframe('4bda29d2-ae98-4893-80a1-7e4c9cb08943','bf9e6581-4688-44ec-a9f3-6b0220b5a914')">Go Back</button><button class="try_examples_button" onclick="window.openInNewTab('4bda29d2-ae98-4893-80a1-7e4c9cb08943','bf9e6581-4688-44ec-a9f3-6b0220b5a914')">Open In Tab</button></div><div id="ff1f013f-988a-4981-8737-79002d4a5a3d" 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)
