From 93ef7d29c7ce86ecc10e1c3461291d5b0fbedf2a Mon Sep 17 00:00:00 2001 From: Benoit Bovy Date: Mon, 30 May 2016 16:05:14 +0200 Subject: [PATCH] added documentation (indexing) --- doc/indexing.rst | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/doc/indexing.rst b/doc/indexing.rst index a64e20610d5..61ae946ced4 100644 --- a/doc/indexing.rst +++ b/doc/indexing.rst @@ -294,6 +294,27 @@ elements that are fully masked: arr2.where(arr2.y < 2, drop=True) +.. _multi-index indexing: + +Multi-index indexing +-------------------- + +The ``loc`` and ``sel`` methods of ``Dataset`` and ``DataArray`` both accept +dictionaries for indexing on multi-index dimensions: + +.. ipython:: python + + idx = pd.MultiIndex.from_product([list('abc'), [0, 1]], + names=('one', 'two')) + da_midx = xr.DataArray(range(6), [('x', idx)]) + da_midx + da_midx.sel(x={'one': 'a', 'two': 0}) + da_midx.loc[{'one': 'a'}, ...] + +As shown in the last example above, xarray handles partial selection on +pandas multi-index ; it automatically renames the dimension and replaces the +coordinate when a single index is returned (level drop). + Multi-dimensional indexing --------------------------