# xarray.DataArray.query

#### DataArray.query(queries=None, parser='pandas', engine=None, missing_dims='raise', \*\*queries_kwargs)[[source]](https://github.com/pydata/xarray/blob/main/xarray/core/dataarray.py#L6658-L6735)

Return a new data array indexed along the specified
dimension(s), where the indexers are given as strings containing
Python expressions to be evaluated against the values in the array.

* **Parameters:**
  * **queries** ([dict-like](https://docs.python.org/3/glossary.html#term-mapping) or [`None`](https://docs.python.org/3/builtins/constants.html#None), *optional*) – A dict-like with keys matching dimensions and values given by strings
    containing Python expressions to be evaluated against the data variables
    in the dataset. The expressions will be evaluated using the pandas
    eval() function, and can contain any valid Python expressions but cannot
    contain any Python statements.
  * **parser** (`{"pandas", "python"}`, *default*: `"pandas"`) – The parser to use to construct the syntax tree from the expression.
    The default of ‘pandas’ parses code slightly different than standard
    Python. Alternatively, you can parse an expression using the ‘python’
    parser to retain strict Python semantics.
  * **engine** (`{"python", "numexpr", None}`, *default*: [`None`](https://docs.python.org/3/builtins/constants.html#None)) – The engine used to evaluate the expression. Supported engines are:
    - None: tries to use numexpr, falls back to python
    - “numexpr”: evaluates expressions using numexpr
    - “python”: performs operations as if you had eval’d in top level python
  * **missing_dims** (`{"raise", "warn", "ignore"}`, *default*: `"raise"`) – What to do if dimensions that should be selected from are not present in the
    DataArray:
    - “raise”: raise an exception
    - “warn”: raise a warning, and ignore the missing dimensions
    - “ignore”: ignore the missing dimensions
  * **\*\*queries_kwargs** (`{dim: query, ...}`, *optional*) – The keyword arguments form of `queries`.
    One of queries or queries_kwargs must be provided.
* **Returns:**
  **obj** ([`DataArray`](xarray.DataArray.html.md#xarray.DataArray)) – A new DataArray with the same contents as this dataset, indexed by
  the results of the appropriate queries.

#### SEE ALSO
[`DataArray.isel`](xarray.DataArray.isel.html.md#xarray.DataArray.isel), [`Dataset.query`](xarray.Dataset.query.html.md#xarray.Dataset.query), [`pandas.eval`](https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.eval.html#pandas.eval)

### Examples

<div class="try_examples_button_container"><button class="try_examples_button" onclick="window.tryExamplesShowIframe('afa93fd9-b60d-4504-814d-7d69f8df9d50','d3126bea-7eee-48cd-8964-b7c2a8b868e5','d527ba9d-86a2-4f3f-96a1-af3db2d76bb2','../lite/tree/../notebooks/index.html?path=042ce456_4643_4fcc_b7ed_f222a065e353.ipynb','None')">Try it in your browser!</button></div>
```pycon
>>> da = xr.DataArray(np.arange(0, 5, 1), dims="x", name="a")
>>> da
<xarray.DataArray 'a' (x: 5)> Size: 40B
array([0, 1, 2, 3, 4])
Dimensions without coordinates: x
>>> da.query(x="a > 2")
<xarray.DataArray 'a' (x: 2)> Size: 16B
array([3, 4])
Dimensions without coordinates: x
```

<div id="d527ba9d-86a2-4f3f-96a1-af3db2d76bb2" class="try_examples_outer_iframe  hidden"><div class="try_examples_button_container"><button class="try_examples_button" onclick="window.tryExamplesHideIframe('afa93fd9-b60d-4504-814d-7d69f8df9d50','d527ba9d-86a2-4f3f-96a1-af3db2d76bb2')">Go Back</button><button class="try_examples_button" onclick="window.openInNewTab('afa93fd9-b60d-4504-814d-7d69f8df9d50','d527ba9d-86a2-4f3f-96a1-af3db2d76bb2')">Open In Tab</button></div><div id="d3126bea-7eee-48cd-8964-b7c2a8b868e5" class="jupyterlite_sphinx_iframe_container"></div></div><script>document.addEventListener("DOMContentLoaded", function() {window.loadTryExamplesConfig("../try_examples.json");});</script>
