# xarray.Dataset.eval

#### Dataset.eval(statement, , parser=Default.token)[[source]](https://github.com/pydata/xarray/blob/main/xarray/core/dataset.py#L9836-L9939)

Calculate an expression supplied as a string in the context of the dataset.

This is currently experimental; the API may change particularly around
assignments, which currently return a `Dataset` with the additional variable.

Logical operators (`and`, `or`, `not`) are automatically transformed
to bitwise operators (`&`, `|`, `~`) which work element-wise on arrays.

* **Parameters:**
  **statement** ([`str`](https://docs.python.org/3/builtins/stdtypes.html#str)) – String containing the Python-like expression to evaluate.
* **Returns:**
  **result** ([`Dataset`](xarray.Dataset.html.md#xarray.Dataset) or [`DataArray`](xarray.DataArray.html.md#xarray.DataArray), `depending on whether ``statement`` contains an\`) – assignment.

#### WARNING
Like `pd.eval()`, this method should not be used with untrusted input.

### Examples

<div class="try_examples_button_container"><button class="try_examples_button" onclick="window.tryExamplesShowIframe('59338857-bad5-4162-ab18-65bd00669f25','b1ee7391-a2ca-4916-8b93-181760c817f0','e84982b2-9809-4cd7-93f1-10458ab76b57','../lite/tree/../notebooks/index.html?path=ea625f82_77c8_4228_be8d_e24c251d3bf5.ipynb','None')">Try it in your browser!</button></div>
```pycon
>>> ds = xr.Dataset(
...     {"a": ("x", np.arange(0, 5, 1)), "b": ("x", np.linspace(0, 1, 5))}
... )
>>> ds
<xarray.Dataset> Size: 80B
Dimensions:  (x: 5)
Dimensions without coordinates: x
Data variables:
    a        (x) int64 40B 0 1 2 3 4
    b        (x) float64 40B 0.0 0.25 0.5 0.75 1.0
```

```pycon
>>> ds.eval("a + b")
<xarray.DataArray (x: 5)> Size: 40B
array([0.  , 1.25, 2.5 , 3.75, 5.  ])
Dimensions without coordinates: x
```

```pycon
>>> ds.eval("c = a + b")
<xarray.Dataset> Size: 120B
Dimensions:  (x: 5)
Dimensions without coordinates: x
Data variables:
    a        (x) int64 40B 0 1 2 3 4
    b        (x) float64 40B 0.0 0.25 0.5 0.75 1.0
    c        (x) float64 40B 0.0 1.25 2.5 3.75 5.0
```

<div id="e84982b2-9809-4cd7-93f1-10458ab76b57" class="try_examples_outer_iframe  hidden"><div class="try_examples_button_container"><button class="try_examples_button" onclick="window.tryExamplesHideIframe('59338857-bad5-4162-ab18-65bd00669f25','e84982b2-9809-4cd7-93f1-10458ab76b57')">Go Back</button><button class="try_examples_button" onclick="window.openInNewTab('59338857-bad5-4162-ab18-65bd00669f25','e84982b2-9809-4cd7-93f1-10458ab76b57')">Open In Tab</button></div><div id="b1ee7391-a2ca-4916-8b93-181760c817f0" class="jupyterlite_sphinx_iframe_container"></div></div><script>document.addEventListener("DOMContentLoaded", function() {window.loadTryExamplesConfig("../try_examples.json");});</script>
