# xarray.Dataset.map

#### Dataset.map(func, keep_attrs=None, args=(), \*\*kwargs)[[source]](https://github.com/pydata/xarray/blob/main/xarray/core/dataset.py#L7059-L7143)

Apply a function to each data variable in this dataset.

* **Parameters:**
  * **func** ([`callable()`](https://docs.python.org/3/builtins/functions.html#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`](https://docs.python.org/3/builtins/functions.html#bool) or [`None`](https://docs.python.org/3/builtins/constants.html#None), *optional*) – If True, both the dataset’s and variables’ attributes (attrs) will be
    combined from the original objects and the function results using the
    `drop_conflicts` strategy: matching attrs are kept, conflicting attrs
    are dropped. If False, the new dataset and variables will have only
    the attributes set by the function.
  * **args** ([iterable](https://docs.python.org/3/glossary.html#term-iterable), *optional*) – Positional arguments passed on to func.
  * **\*\*kwargs** (`Any`) – Keyword arguments passed on to func.
* **Returns:**
  **applied** ([`Dataset`](xarray.Dataset.html.md#xarray.Dataset)) – Resulting dataset from applying `func` to each data variable.

### Examples

<div class="try_examples_button_container"><button class="try_examples_button" onclick="window.tryExamplesShowIframe('92164938-79ef-4393-98bf-421ac7891384','23ebff0f-70ce-459d-9b94-2aea18f1b751','fad20524-363e-4e55-927a-aea750a5b523','../lite/tree/../notebooks/index.html?path=a5b9c93e_811b_4160_be8d_94bd5b6b2a94.ipynb','None')">Try it in your browser!</button></div>
```pycon
>>> da = xr.DataArray(np.random.randn(2, 3))
>>> ds = xr.Dataset({"foo": da, "bar": ("x", [-1, 2])})
>>> ds
<xarray.Dataset> Size: 64B
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 48B 1.764 0.4002 0.9787 2.241 1.868 -0.9773
    bar      (x) int64 16B -1 2
>>> ds.map(np.fabs)
<xarray.Dataset> Size: 64B
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 48B 1.764 0.4002 0.9787 2.241 1.868 0.9773
    bar      (x) float64 16B 1.0 2.0
```

<div id="fad20524-363e-4e55-927a-aea750a5b523" class="try_examples_outer_iframe  hidden"><div class="try_examples_button_container"><button class="try_examples_button" onclick="window.tryExamplesHideIframe('92164938-79ef-4393-98bf-421ac7891384','fad20524-363e-4e55-927a-aea750a5b523')">Go Back</button><button class="try_examples_button" onclick="window.openInNewTab('92164938-79ef-4393-98bf-421ac7891384','fad20524-363e-4e55-927a-aea750a5b523')">Open In Tab</button></div><div id="23ebff0f-70ce-459d-9b94-2aea18f1b751" class="jupyterlite_sphinx_iframe_container"></div></div><script>document.addEventListener("DOMContentLoaded", function() {window.loadTryExamplesConfig("../try_examples.json");});</script>
