xarray.Dataset.quantile¶
-
Dataset.
quantile
(q, dim=None, interpolation='linear', numeric_only=False, keep_attrs=None, skipna=True)¶ Compute the qth quantile of the data along the specified dimension.
Returns the qth quantiles(s) of the array elements for each variable in the Dataset.
- Parameters
q (
float
or array-like offloat
) – Quantile to compute, which must be between 0 and 1 inclusive.dim (
str
or sequence ofstr
, optional) – Dimension(s) over which to apply quantile.interpolation (
{"linear", "lower", "higher", "midpoint", "nearest"}
, default:"linear"
) – This optional parameter specifies the interpolation method to use when the desired quantile lies between two data pointsi < j
:linear:
i + (j - i) * fraction
, wherefraction
is the fractional part of the index surrounded byi
andj
.lower:
i
.higher:
j
.nearest:
i
orj
, whichever is nearest.midpoint:
(i + j) / 2
.
keep_attrs (
bool
, 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.numeric_only (
bool
, optional) – If True, only applyfunc
to variables with a numeric dtype.skipna (
bool
, optional) – Whether to skip missing values when aggregating.
- Returns
quantiles (
Dataset
) – If q is a single quantile, then the result is a scalar for each variable in data_vars. If multiple percentiles are given, first axis of the result corresponds to the quantile and a quantile dimension is added to the return Dataset. The other dimensions are the dimensions that remain after the reduction of the array.
Examples
>>> ds = xr.Dataset( ... {"a": (("x", "y"), [[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]}, ... ) >>> ds.quantile(0) # or ds.quantile(0, dim=...) <xarray.Dataset> Dimensions: () Coordinates: quantile float64 0.0 Data variables: a float64 0.7 >>> ds.quantile(0, dim="x") <xarray.Dataset> Dimensions: (y: 4) Coordinates: * y (y) float64 1.0 1.5 2.0 2.5 quantile float64 0.0 Data variables: a (y) float64 0.7 4.2 2.6 1.5 >>> ds.quantile([0, 0.5, 1]) <xarray.Dataset> Dimensions: (quantile: 3) Coordinates: * quantile (quantile) float64 0.0 0.5 1.0 Data variables: a (quantile) float64 0.7 3.4 9.4 >>> ds.quantile([0, 0.5, 1], dim="x") <xarray.Dataset> Dimensions: (quantile: 3, y: 4) Coordinates: * y (y) float64 1.0 1.5 2.0 2.5 * quantile (quantile) float64 0.0 0.5 1.0 Data variables: a (quantile, y) float64 0.7 4.2 2.6 1.5 3.6 ... 1.7 6.5 7.3 9.4 1.9