MCPcopy
hub / github.com/pydata/xarray / from_pandas_multiindex

Method from_pandas_multiindex

xarray/core/coordinates.py:405–430  ·  view source on GitHub ↗

Wrap a pandas multi-index as Xarray coordinates (dimension + levels). The returned coordinate variables can be directly assigned to a :py:class:`~xarray.Dataset` or :py:class:`~xarray.DataArray` via the ``coords`` argument of their constructor. Parameters --

(cls, midx: pd.MultiIndex, dim: Hashable)

Source from the content-addressed store, hash-verified

403
404 @classmethod
405 def from_pandas_multiindex(cls, midx: pd.MultiIndex, dim: Hashable) -> Self:
406 """Wrap a pandas multi-index as Xarray coordinates (dimension + levels).
407
408 The returned coordinate variables can be directly assigned to a
409 :py:class:`~xarray.Dataset` or :py:class:`~xarray.DataArray` via the
410 ``coords`` argument of their constructor.
411
412 Parameters
413 ----------
414 midx : :py:class:`pandas.MultiIndex`
415 Pandas multi-index object.
416 dim : str
417 Dimension name.
418
419 Returns
420 -------
421 coords : Coordinates
422 A collection of Xarray indexed coordinates created from the multi-index.
423
424 """
425 xr_idx = PandasMultiIndex(midx, dim)
426
427 variables = xr_idx.create_variables()
428 indexes = dict.fromkeys(variables, xr_idx)
429
430 return cls(coords=variables, indexes=indexes)
431
432 @property
433 def _names(self) -> set[Hashable]:

Callers 15

_factorize_dummyMethod · 0.80
factorizeMethod · 0.80
create_test_multiindexFunction · 0.80
test_repr_multiindexMethod · 0.80
test_sel_drop_mindexMethod · 0.80
test_drop_indexesMethod · 0.80
test_swap_dimsMethod · 0.80

Calls 2

create_variablesMethod · 0.95
PandasMultiIndexClass · 0.90