# xarray.Dataset.map

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

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('2b3e3a0b-584c-46b1-b509-85e3b7a7dd67','53fa00c2-8d27-4d61-8bfc-288902b7eda0','911800f2-debc-427c-8ce9-1071807313a4','../lite/tree/../notebooks/index.html?path=68ec1e54_354a_45b9_b6eb_652da7f7f6a3.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="911800f2-debc-427c-8ce9-1071807313a4" class="try_examples_outer_iframe  hidden"><div class="try_examples_button_container"><button class="try_examples_button" onclick="window.tryExamplesHideIframe('2b3e3a0b-584c-46b1-b509-85e3b7a7dd67','911800f2-debc-427c-8ce9-1071807313a4')">Go Back</button><button class="try_examples_button" onclick="window.openInNewTab('2b3e3a0b-584c-46b1-b509-85e3b7a7dd67','911800f2-debc-427c-8ce9-1071807313a4')">Open In Tab</button></div><div id="53fa00c2-8d27-4d61-8bfc-288902b7eda0" class="jupyterlite_sphinx_iframe_container"></div></div><script>document.addEventListener("DOMContentLoaded", function() {window.loadTryExamplesConfig("../try_examples.json");});</script>
