xarray.DataTree.assign

xarray.DataTree.assign#

DataTree.assign(items=None, **items_kwargs)[source]#

Assign new data variables or child nodes to a DataTree, returning a new object with all the original items in addition to the new ones.

Parameters
  • items (mapping of hashable to Any) – Mapping from variable or child node names to the new values. If the new values are callable, they are computed on the Dataset and assigned to new data variables. If the values are not callable, (e.g. a DataTree, DataArray, scalar, or array), they are simply assigned.

  • **items_kwargs – The keyword arguments form of variables. One of variables or variables_kwargs must be provided.

Returns

dt (DataTree) – A new DataTree with the new variables or children in addition to all the existing items.

Notes

Since kwargs is a dictionary, the order of your arguments may not be preserved, and so the order of the new variables is not well-defined. Assigning multiple items within the same assign is possible, but you cannot reference other variables created within the same assign call.