shnitsel.core.xrhelpers.assign_levels¶
- assign_levels(obj, levels=None, **levels_kwargs)¶
Assign new values to levels of MultiIndexes in
obj
- Parameters:
obj (Dataset | DataArray) – An
xarray
object with at least one MultiIndexlevels (dict[str, Buffer | _SupportsArray[dtype[Any]] | _NestedSequence[_SupportsArray[dtype[Any]]] | bool | int | float | complex | str | bytes | _NestedSequence[bool | int | float | complex | str | bytes]] | None) – A mapping whose keys are the names of the levels and whose values are the levels to assign. The mapping will be passed to
xarray.DataArray.assign_coords()
(or thexarray.Dataset
equivalent).optional – A mapping whose keys are the names of the levels and whose values are the levels to assign. The mapping will be passed to
xarray.DataArray.assign_coords()
(or thexarray.Dataset
equivalent).levels_kwargs (Buffer | _SupportsArray[dtype[Any]] | _NestedSequence[_SupportsArray[dtype[Any]]] | bool | int | float | complex | str | bytes | _NestedSequence[bool | int | float | complex | str | bytes])
- Return type:
A new object with the new level values replacing the old level values.
- Raises:
ValueError – If levels are provided in both keyword and dictionary form.