xarray.DataArray.assign_attrs

xarray.DataArray.assign_attrs#

DataArray.assign_attrs(*args, **kwargs)[source]#

Assign new attrs to this object.

Returns a new object equivalent to self.attrs.update(*args, **kwargs).

Parameters
  • *args – positional arguments passed into attrs.update.

  • **kwargs – keyword arguments passed into attrs.update.

Examples

>>> dataset = xr.Dataset({"temperature": [25, 30, 27]})
>>> dataset
<xarray.Dataset> Size: 24B
Dimensions:      (temperature: 3)
Coordinates:
  * temperature  (temperature) int64 24B 25 30 27
Data variables:
    *empty*
>>> new_dataset = dataset.assign_attrs(
...     units="Celsius", description="Temperature data"
... )
>>> new_dataset
<xarray.Dataset> Size: 24B
Dimensions:      (temperature: 3)
Coordinates:
  * temperature  (temperature) int64 24B 25 30 27
Data variables:
    *empty*
Attributes:
    units:        Celsius
    description:  Temperature data

# Attributes of the new dataset

>>> new_dataset.attrs
{'units': 'Celsius', 'description': 'Temperature data'}
Returns

assigned (same type as caller) – A new object with the new attrs in addition to the existing data.

See also

Dataset.assign