# xarray.DataArray.quantile

#### DataArray.quantile(q, dim=None, , method='linear', keep_attrs=None, skipna=None, interpolation=None)[[source]](https://github.com/pydata/xarray/blob/v2026.09.0/xarray/core/dataarray.py#L5435-L5552)

Compute the qth quantile of the data along the specified dimension.

Returns the qth quantiles(s) of the array elements.

* **Parameters:**
  * **q** ([`float`](https://docs.python.org/3/builtins/functions.html#float) or [array-like](https://numpy.org/doc/stable/glossary.html#term-array_like) of [`float`](https://docs.python.org/3/builtins/functions.html#float)) – Quantile to compute, which must be between 0 and 1 inclusive.
  * **dim** ([`str`](xarray.DataArray.str.html.md#xarray.DataArray.str) or `Iterable` of `Hashable`, *optional*) – Dimension(s) over which to apply quantile.
  * **method** ([`str`](xarray.DataArray.str.html.md#xarray.DataArray.str), *default*: `"linear"`) – This optional parameter specifies the interpolation method to use when the
    desired quantile lies between two data points. The options sorted by their R
    type as summarized in the H&F paper <sup>[1](#id3)</sup> are:
    > 1. “inverted_cdf”
    > 2. “averaged_inverted_cdf”
    > 3. “closest_observation”
    > 4. “interpolated_inverted_cdf”
    > 5. “hazen”
    > 6. “weibull”
    > 7. “linear”  (default)
    > 8. “median_unbiased”
    > 9. “normal_unbiased”

    The first three methods are discontiuous. The following discontinuous
    variations of the default “linear” (7.) option are also available:
    > * “lower”
    > * “higher”
    > * “midpoint”
    > * “nearest”

    See [`numpy.quantile()`](https://numpy.org/doc/stable/reference/generated/numpy.quantile.html#numpy.quantile) or <sup>[1](#id3)</sup> for details. The “method” argument
    was previously called “interpolation”, renamed in accordance with numpy
    version 1.22.0.
  * **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, the dataset’s attributes (attrs) will be copied from
    the original object to the new one.  If False (default), the new
    object will be returned without attributes.
  * **skipna** ([`bool`](https://docs.python.org/3/builtins/functions.html#bool) or [`None`](https://docs.python.org/3/builtins/constants.html#None), *optional*) – If True, skip missing values (as marked by NaN). By default, only
    skips missing values for float dtypes; other dtypes either do not
    have a sentinel missing value (int) or skipna=True has not been
    implemented (object, datetime64 or timedelta64).
* **Returns:**
  **quantiles** ([`DataArray`](xarray.DataArray.html.md#xarray.DataArray)) – If q is a single quantile, then the result
  is a scalar. If multiple percentiles are given, first axis of
  the result corresponds to the quantile and a quantile dimension
  is added to the return array. The other dimensions are the
  dimensions that remain after the reduction of the array.

#### SEE ALSO
[`numpy.nanquantile`](https://numpy.org/doc/stable/reference/generated/numpy.nanquantile.html#numpy.nanquantile), [`numpy.quantile`](https://numpy.org/doc/stable/reference/generated/numpy.quantile.html#numpy.quantile), [`pandas.Series.quantile`](https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.Series.quantile.html#pandas.Series.quantile), [`Dataset.quantile`](xarray.Dataset.quantile.html.md#xarray.Dataset.quantile)

### Examples

<div class="try_examples_button_container"><button class="try_examples_button" onclick="window.tryExamplesShowIframe('0ef1493e-9c1a-464e-a3d5-3ec620241f09','dc688e75-3cbe-4fb2-a432-31522ce856e4','1803503e-0c36-482a-9857-7a9326afdcee','../lite/tree/../notebooks/index.html?path=29ff6bf7_bc70_4088_a2fc_f07362c2880c.ipynb','None')">Try it in your browser!</button></div>
```pycon
>>> da = xr.DataArray(
...     data=[[0.7, 4.2, 9.4, 1.5], [6.5, 7.3, 2.6, 1.9]],
...     coords={"x": [7, 9], "y": [1, 1.5, 2, 2.5]},
...     dims=("x", "y"),
... )
>>> da.quantile(0)  # or da.quantile(0, dim=...)
<xarray.DataArray ()> Size: 8B
array(0.7)
Coordinates:
    quantile  float64 8B 0.0
>>> da.quantile(0, dim="x")
<xarray.DataArray (y: 4)> Size: 32B
array([0.7, 4.2, 2.6, 1.5])
Coordinates:
  * y         (y) float64 32B 1.0 1.5 2.0 2.5
    quantile  float64 8B 0.0
>>> da.quantile([0, 0.5, 1])
<xarray.DataArray (quantile: 3)> Size: 24B
array([0.7, 3.4, 9.4])
Coordinates:
  * quantile  (quantile) float64 24B 0.0 0.5 1.0
>>> da.quantile([0, 0.5, 1], dim="x")
<xarray.DataArray (quantile: 3, y: 4)> Size: 96B
array([[0.7 , 4.2 , 2.6 , 1.5 ],
       [3.6 , 5.75, 6.  , 1.7 ],
       [6.5 , 7.3 , 9.4 , 1.9 ]])
Coordinates:
  * quantile  (quantile) float64 24B 0.0 0.5 1.0
  * y         (y) float64 32B 1.0 1.5 2.0 2.5
```

<div id="1803503e-0c36-482a-9857-7a9326afdcee" class="try_examples_outer_iframe  hidden"><div class="try_examples_button_container"><button class="try_examples_button" onclick="window.tryExamplesHideIframe('0ef1493e-9c1a-464e-a3d5-3ec620241f09','1803503e-0c36-482a-9857-7a9326afdcee')">Go Back</button><button class="try_examples_button" onclick="window.openInNewTab('0ef1493e-9c1a-464e-a3d5-3ec620241f09','1803503e-0c36-482a-9857-7a9326afdcee')">Open In Tab</button></div><div id="dc688e75-3cbe-4fb2-a432-31522ce856e4" class="jupyterlite_sphinx_iframe_container"></div></div><script>document.addEventListener("DOMContentLoaded", function() {window.loadTryExamplesConfig("../try_examples.json");});</script>

### References

* <a id='id3'>**[1]**</a> R. J. Hyndman and Y. Fan, “Sample quantiles in statistical packages,” The American Statistician, 50(4), pp. 361-365, 1996
