# xarray.DataArray.to_unstacked_dataset

#### DataArray.to_unstacked_dataset(dim, level=0)[[source]](https://github.com/pydata/xarray/blob/main/xarray/core/dataarray.py#L3187-L3250)

Unstack DataArray expanding to Dataset along a given level of a
stacked coordinate.

This is the inverse operation of Dataset.to_stacked_array.

* **Parameters:**
  * **dim** (`Hashable`) – Name of existing dimension to unstack
  * **level** ([`int`](https://docs.python.org/3/builtins/functions.html#int) or `Hashable`, *default*: `0`) – The MultiIndex level to expand to a dataset along. Can either be
    the integer index of the level or its name.
* **Returns:**
  **unstacked** ([`Dataset`](xarray.Dataset.html.md#xarray.Dataset))

### Examples

<div class="try_examples_button_container"><button class="try_examples_button" onclick="window.tryExamplesShowIframe('72f7c24f-db02-4f5d-9ef4-b4effac0b0ce','4a7ef875-718b-4c25-bfca-d3516fd6ac5a','e242e73c-ccde-4e3e-9572-7a4e8033b3bc','../lite/tree/../notebooks/index.html?path=6fa2afc1_7789_40e0_8ba9_77f58517f081.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])],
... )
>>> data = xr.Dataset({"a": arr, "b": arr.isel(y=0)})
>>> data
<xarray.Dataset> Size: 96B
Dimensions:  (x: 2, y: 3)
Coordinates:
  * x        (x) <U1 8B 'a' 'b'
  * y        (y) int64 24B 0 1 2
Data variables:
    a        (x, y) int64 48B 0 1 2 3 4 5
    b        (x) int64 16B 0 3
>>> stacked = data.to_stacked_array("z", ["x"])
>>> stacked.indexes["z"]
MultiIndex([('a', 0.0),
            ('a', 1.0),
            ('a', 2.0),
            ('b', nan)],
           name='z')
>>> roundtripped = stacked.to_unstacked_dataset(dim="z")
>>> data.identical(roundtripped)
True
```

<div id="e242e73c-ccde-4e3e-9572-7a4e8033b3bc" class="try_examples_outer_iframe  hidden"><div class="try_examples_button_container"><button class="try_examples_button" onclick="window.tryExamplesHideIframe('72f7c24f-db02-4f5d-9ef4-b4effac0b0ce','e242e73c-ccde-4e3e-9572-7a4e8033b3bc')">Go Back</button><button class="try_examples_button" onclick="window.openInNewTab('72f7c24f-db02-4f5d-9ef4-b4effac0b0ce','e242e73c-ccde-4e3e-9572-7a4e8033b3bc')">Open In Tab</button></div><div id="4a7ef875-718b-4c25-bfca-d3516fd6ac5a" class="jupyterlite_sphinx_iframe_container"></div></div><script>document.addEventListener("DOMContentLoaded", function() {window.loadTryExamplesConfig("../try_examples.json");});</script>

#### SEE ALSO
[`Dataset.to_stacked_array`](xarray.Dataset.to_stacked_array.html.md#xarray.Dataset.to_stacked_array)
