# xarray.IndexVariable.stack

#### IndexVariable.stack(dim=None, \*\*dim_kwargs)[[source]](https://github.com/pydata/xarray/blob/main/xarray/core/variable.py#L1754-L1785)

Stack any number of existing dim into a single new dimension.

New dim will be added at the end, and the order of the data
along each new dimension will be in contiguous (C) order.

* **Parameters:**
  * **dim** ([mapping](https://docs.python.org/3/glossary.html#term-mapping) of [hashable](../user-guide/terminology.html.md#term-name) to [`tuple`](https://docs.python.org/3/builtins/stdtypes.html#tuple) of [hashable](../user-guide/terminology.html.md#term-name)) – Mapping of form new_name=(dim1, dim2, …) describing the
    names of new dim, and the existing dim that
    they replace.
  * **\*\*dim_kwargs** – The keyword arguments form of `dim`.
    One of dim or dim_kwargs must be provided.
* **Returns:**
  **stacked** ([`Variable`](xarray.Variable.html.md#xarray.Variable)) – Variable with the same attributes but stacked data.

#### SEE ALSO
[`Variable.unstack`](xarray.Variable.unstack.html.md#xarray.Variable.unstack)
