File tree 1 file changed +21
-0
lines changed
1 file changed +21
-0
lines changed Original file line number Diff line number Diff line change @@ -294,6 +294,27 @@ elements that are fully masked:
294
294
295
295
arr2.where(arr2.y < 2 , drop = True )
296
296
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
+
297
318
Multi-dimensional indexing
298
319
--------------------------
299
320
You can’t perform that action at this time.
0 commit comments