pandas.Series.quantile¶
Return value at the given quantile.
- param q
- float or array-like, default 0.5 (50% quantile)
0 <= q <= 1, the quantile(s) to compute.
- param interpolation
- {‘linear’, ‘lower’, ‘higher’, ‘midpoint’, ‘nearest’}
New in version 0.18.0.
This optional parameter specifies the interpolation method to use, when the desired quantile lies between two data points i and j:
- linear: i + (j - i) * fraction, where fraction is the
fractional part of the index surrounded by i and j.
lower: i.
higher: j.
nearest: i or j whichever is nearest.
midpoint: (i + j) / 2.
- return
float or Series If
q
is an array, a Series will be returned where the index isq
and the values are the quantiles, otherwise a float will be returned.
Limitations¶
Parameter interpolation
is currently unsupported.
Examples¶
import pandas as pd
from numba import njit
@njit
def series_quantile():
s = pd.Series([1, 2, 3, 4])
median = .5 # compute median
out_series = s.quantile(median)
return out_series # Expect median value == 2.5
print(series_quantile())
$ python ./series/series_quantile.py
2.5
See also
- core.window.Rolling.quantile
Calculate the rolling quantile.
Compute the q-th percentile of the data along the specified axis.