MCPcopy
hub / github.com/pandas-dev/pandas / quantile

Method quantile

pandas/core/groupby/groupby.py:4775–4993  ·  view source on GitHub ↗

Return group values at the given quantile, a la numpy.percentile. Parameters ---------- q : float or array-like, default 0.5 (50% quantile) Value(s) between 0 and 1 providing the quantile(s) to compute. interpolation : {'linear', 'lower', 'higher

(
        self,
        q: float | AnyArrayLike = 0.5,
        interpolation: Literal[
            "linear", "lower", "higher", "nearest", "midpoint"
        ] = "linear",
        numeric_only: bool = False,
    )

Source from the content-addressed store, hash-verified

4773
4774 @final
4775 def quantile(
4776 self,
4777 q: float | AnyArrayLike = 0.5,
4778 interpolation: Literal[
4779 "linear", "lower", "higher", "nearest", "midpoint"
4780 ] = "linear",
4781 numeric_only: bool = False,
4782 ):
4783 """
4784 Return group values at the given quantile, a la numpy.percentile.
4785
4786 Parameters
4787 ----------
4788 q : float or array-like, default 0.5 (50% quantile)
4789 Value(s) between 0 and 1 providing the quantile(s) to compute.
4790 interpolation : {'linear', 'lower', 'higher', 'midpoint', 'nearest'}
4791 Method to use when the desired quantile falls between two points.
4792 numeric_only : bool, default False
4793 Include only `float`, `int` or `boolean` data.
4794
4795 .. versionchanged:: 2.0.0
4796
4797 numeric_only now defaults to ``False``.
4798
4799 Returns
4800 -------
4801 Series or DataFrame
4802 Return type determined by caller of GroupBy object.
4803
4804 See Also
4805 --------
4806 Series.quantile : Similar method for Series.
4807 DataFrame.quantile : Similar method for DataFrame.
4808 numpy.percentile : NumPy method to compute qth percentile.
4809
4810 Examples
4811 --------
4812 >>> df = pd.DataFrame(
4813 ... [["a", 1], ["a", 2], ["a", 3], ["b", 1], ["b", 3], ["b", 5]],
4814 ... columns=["key", "val"],
4815 ... )
4816 >>> df.groupby("key").quantile()
4817 val
4818 key
4819 a 2.0
4820 b 3.0
4821 """
4822 mgr = self._get_data_to_aggregate(numeric_only=numeric_only, name="quantile")
4823 obj = self._wrap_agged_manager(mgr)
4824 splitter = self._grouper._get_splitter(obj)
4825 sdata = splitter._sorted_data
4826
4827 starts, ends = lib.generate_slices(splitter._slabels, splitter.ngroups)
4828
4829 def pre_processor(vals: ArrayLike) -> tuple[np.ndarray, DtypeObj | None]:
4830 if isinstance(vals.dtype, StringDtype) or is_object_dtype(vals.dtype):
4831 raise TypeError(
4832 f"dtype '{vals.dtype}' does not support operation 'quantile'"

Callers

nothing calls this directly

Calls 6

_get_splitterMethod · 0.80
_wrap_agged_managerMethod · 0.45
arrayMethod · 0.45
grouped_reduceMethod · 0.45

Tested by

no test coverage detected