🍾 Xarray is now 10 years old! 🎉

xarray.core.weighted.DatasetWeighted.quantile

xarray.core.weighted.DatasetWeighted.quantile#

DatasetWeighted.quantile(q, *, dim=None, keep_attrs=None, skipna=True)[source]#

Apply a weighted quantile to this Dataset’s data along some dimension(s).

Weights are interpreted as sampling weights (or probability weights) and describe how a sample is scaled to the whole population [1]. There are other possible interpretations for weights, precision weights describing the precision of observations, or frequency weights counting the number of identical observations, however, they are not implemented here.

For compatibility with NumPy’s non-weighted quantile (which is used by DataArray.quantile and Dataset.quantile), the only interpolation method supported by this weighted version corresponds to the default “linear” option of numpy.quantile. This is “Type 7” option, described in Hyndman and Fan (1996) [2]. The implementation is largely inspired by a blog post from A. Akinshin’s [3].

Parameters:
  • q (float or sequence of float) – Quantile to compute, which must be between 0 and 1 inclusive.

  • dim (str or sequence of str, optional) – Dimension(s) over which to apply the weighted quantile.

  • skipna (bool, 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).

  • keep_attrs (bool, optional) – If True, the attributes (attrs) will be copied from the original object to the new one. If False (default), the new object will be returned without attributes.

Returns:

quantiles (Dataset) – New Dataset object with weighted quantile applied to its data and the indicated dimension(s) removed.

See also

numpy.nanquantile, pandas.Series.quantile, Dataset.quantile, DataArray.quantile

Notes

Returns NaN if the weights sum to 0.0 along the reduced dimension(s).

References