xarray.Dataset.assign_attrs#

Dataset.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>
Dimensions:      (temperature: 3)
Coordinates:
  * temperature  (temperature) int64 25 30 27
Data variables:
    *empty*
>>> new_dataset = dataset.assign_attrs(
...     units="Celsius", description="Temperature data"
... )
>>> new_dataset
<xarray.Dataset>
Dimensions:      (temperature: 3)
Coordinates:
  * temperature  (temperature) int64 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