đźŤľ Xarray is now 10 years old! đźŽ‰

# xarray.Dataset.map#

Dataset.map(func, keep_attrs=None, args=(), **kwargs)[source]#

Apply a function to each data variable in this dataset

Parameters:
• func (`callable()`) â€“ Function which can be called in the form func(x, *args, **kwargs) to transform each DataArray x in this dataset into another DataArray.

• keep_attrs (`bool` or `None`, optional) â€“ If True, both the datasetâ€™s and variablesâ€™ attributes (attrs) will be copied from the original objects to the new ones. If False, the new dataset and variables will be returned without copying the attributes.

• args (iterable, optional) â€“ Positional arguments passed on to func.

• **kwargs (`Any`) â€“ Keyword arguments passed on to func.

Returns:

applied (`Dataset`) â€“ Resulting dataset from applying `func` to each data variable.

Examples

```>>> da = xr.DataArray(np.random.randn(2, 3))
>>> ds = xr.Dataset({"foo": da, "bar": ("x", [-1, 2])})
>>> ds
<xarray.Dataset>
Dimensions:  (dim_0: 2, dim_1: 3, x: 2)
Dimensions without coordinates: dim_0, dim_1, x
Data variables:
foo      (dim_0, dim_1) float64 1.764 0.4002 0.9787 2.241 1.868 -0.9773
bar      (x) int64 -1 2
>>> ds.map(np.fabs)
<xarray.Dataset>
Dimensions:  (dim_0: 2, dim_1: 3, x: 2)
Dimensions without coordinates: dim_0, dim_1, x
Data variables:
foo      (dim_0, dim_1) float64 1.764 0.4002 0.9787 2.241 1.868 0.9773
bar      (x) float64 1.0 2.0
```