# xarray.Dataset.eval

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

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('8d382f04-180a-447e-ad67-76ebb278449e','18436d23-5a9f-4a59-98d1-267ad3b25de0','5ab6470d-a8fb-46e1-a558-f8ef8176be05','../lite/tree/../notebooks/index.html?path=5594e2f1_2425_498f_901d_1d2f2818e271.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="5ab6470d-a8fb-46e1-a558-f8ef8176be05" class="try_examples_outer_iframe  hidden"><div class="try_examples_button_container"><button class="try_examples_button" onclick="window.tryExamplesHideIframe('8d382f04-180a-447e-ad67-76ebb278449e','5ab6470d-a8fb-46e1-a558-f8ef8176be05')">Go Back</button><button class="try_examples_button" onclick="window.openInNewTab('8d382f04-180a-447e-ad67-76ebb278449e','5ab6470d-a8fb-46e1-a558-f8ef8176be05')">Open In Tab</button></div><div id="18436d23-5a9f-4a59-98d1-267ad3b25de0" class="jupyterlite_sphinx_iframe_container"></div></div><script>document.addEventListener("DOMContentLoaded", function() {window.loadTryExamplesConfig("../try_examples.json");});</script>
