# xarray.core.groupby.DataArrayGroupBy.quantile

#### DataArrayGroupBy.quantile(q, dim=None, , method='linear', keep_attrs=None, skipna=None, interpolation=None)[[source]](https://github.com/pydata/xarray/blob/main/xarray/core/groupby.py#L1352-L1503)

Compute the qth quantile over each array in the groups and
concatenate them together into a new array.

* **Parameters:**
  * **q** ([`float`](https://docs.python.org/3/builtins/functions.html#float) or [sequence](https://docs.python.org/3/glossary.html#term-sequence) of [`float`](https://docs.python.org/3/builtins/functions.html#float)) – Quantile to compute, which must be between 0 and 1
    inclusive.
  * **dim** ([`str`](https://docs.python.org/3/builtins/stdtypes.html#str) or `Iterable` of `Hashable`, *optional*) – Dimension(s) over which to apply quantile.
    Defaults to the grouped dimension.
  * **method** ([`str`](https://docs.python.org/3/builtins/stdtypes.html#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), *default*: [`None`](https://docs.python.org/3/builtins/constants.html#None)) – If True, the dataarray’s attributes (attrs) will be copied from
    the original object to the new one.  If False, 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), *default*: [`None`](https://docs.python.org/3/builtins/constants.html#None)) – 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** ([`Variable`](xarray.Variable.html.md#xarray.Variable)) – 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. In either case 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`, `DataArray.quantile`

### Examples

<div class="try_examples_button_container"><button class="try_examples_button" onclick="window.tryExamplesShowIframe('bd6ac49b-4785-4e32-aa1d-daf5ea3e79ff','28ce4fd8-6cf1-4578-a791-3f5085c82bb1','ea776973-63e1-4e25-ac56-066a08d3ea1e','../lite/tree/../notebooks/index.html?path=d8d04c94_bd9c_4ed7_8224_4cd4b6798366.ipynb','None')">Try it in your browser!</button></div>
```pycon
>>> da = xr.DataArray(
...     [[1.3, 8.4, 0.7, 6.9], [0.7, 4.2, 9.4, 1.5], [6.5, 7.3, 2.6, 1.9]],
...     coords={"x": [0, 0, 1], "y": [1, 1, 2, 2]},
...     dims=("x", "y"),
... )
>>> ds = xr.Dataset({"a": da})
>>> da.groupby("x").quantile(0)
<xarray.DataArray (x: 2, y: 4)> Size: 64B
array([[0.7, 4.2, 0.7, 1.5],
       [6.5, 7.3, 2.6, 1.9]])
Coordinates:
  * x         (x) int64 16B 0 1
  * y         (y) int64 32B 1 1 2 2
    quantile  float64 8B 0.0
>>> ds.groupby("y").quantile(0, dim=...)
<xarray.Dataset> Size: 40B
Dimensions:   (y: 2)
Coordinates:
  * y         (y) int64 16B 1 2
    quantile  float64 8B 0.0
Data variables:
    a         (y) float64 16B 0.7 0.7
>>> da.groupby("x").quantile([0, 0.5, 1])
<xarray.DataArray (x: 2, y: 4, quantile: 3)> Size: 192B
array([[[0.7 , 1.  , 1.3 ],
        [4.2 , 6.3 , 8.4 ],
        [0.7 , 5.05, 9.4 ],
        [1.5 , 4.2 , 6.9 ]],

       [[6.5 , 6.5 , 6.5 ],
        [7.3 , 7.3 , 7.3 ],
        [2.6 , 2.6 , 2.6 ],
        [1.9 , 1.9 , 1.9 ]]])
Coordinates:
  * x         (x) int64 16B 0 1
  * y         (y) int64 32B 1 1 2 2
  * quantile  (quantile) float64 24B 0.0 0.5 1.0
>>> ds.groupby("y").quantile([0, 0.5, 1], dim=...)
<xarray.Dataset> Size: 88B
Dimensions:   (y: 2, quantile: 3)
Coordinates:
  * y         (y) int64 16B 1 2
  * quantile  (quantile) float64 24B 0.0 0.5 1.0
Data variables:
    a         (y, quantile) float64 48B 0.7 5.35 8.4 0.7 2.25 9.4
```

<div id="ea776973-63e1-4e25-ac56-066a08d3ea1e" class="try_examples_outer_iframe  hidden"><div class="try_examples_button_container"><button class="try_examples_button" onclick="window.tryExamplesHideIframe('bd6ac49b-4785-4e32-aa1d-daf5ea3e79ff','ea776973-63e1-4e25-ac56-066a08d3ea1e')">Go Back</button><button class="try_examples_button" onclick="window.openInNewTab('bd6ac49b-4785-4e32-aa1d-daf5ea3e79ff','ea776973-63e1-4e25-ac56-066a08d3ea1e')">Open In Tab</button></div><div id="28ce4fd8-6cf1-4578-a791-3f5085c82bb1" 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
