Skip to content

Commit 93ef7d2

Browse files
author
Benoit Bovy
committed
added documentation (indexing)
1 parent eb7a12e commit 93ef7d2

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

doc/indexing.rst

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -294,6 +294,27 @@ elements that are fully masked:
294294
295295
arr2.where(arr2.y < 2, drop=True)
296296
297+
.. _multi-index indexing:
298+
299+
Multi-index indexing
300+
--------------------
301+
302+
The ``loc`` and ``sel`` methods of ``Dataset`` and ``DataArray`` both accept
303+
dictionaries for indexing on multi-index dimensions:
304+
305+
.. ipython:: python
306+
307+
idx = pd.MultiIndex.from_product([list('abc'), [0, 1]],
308+
names=('one', 'two'))
309+
da_midx = xr.DataArray(range(6), [('x', idx)])
310+
da_midx
311+
da_midx.sel(x={'one': 'a', 'two': 0})
312+
da_midx.loc[{'one': 'a'}, ...]
313+
314+
As shown in the last example above, xarray handles partial selection on
315+
pandas multi-index ; it automatically renames the dimension and replaces the
316+
coordinate when a single index is returned (level drop).
317+
297318
Multi-dimensional indexing
298319
--------------------------
299320

0 commit comments

Comments
 (0)