pandas.core.window.rolling.Rolling.quantile#

Rolling.quantile(q, interpolation='linear', numeric_only=False)[源代码]#

计算滚动分位数。

Parameters:
quantilefloat

要计算的分位数。0 <= quantile <= 1。

自 2.1.0 版本弃用: 此参数将在未来版本中重命名为 ‘q’。

interpolation{‘linear’, ‘lower’, ‘higher’, ‘midpoint’, ‘nearest’}

这个可选参数指定了当所需分位数位于两个数据点 ij 之间时要使用的插值方法:

  • linear: i + (j - i) * fraction,其中 fraction 是位于 ij 之间的索引的分数部分。

  • lower: i

  • higher: j

  • nearest: 最接近的 ij

  • midpoint: (i + j) / 2。

numeric_onlybool,默认 False

仅包括浮点数、整数、布尔列。

在 1.5.0 版本加入.

Returns:
Series 或 DataFrame

返回类型与原始对象相同,并具有 np.float64 数据类型。

参见

pandas.Series.rolling

使用 Series 数据调用滚动。

pandas.DataFrame.rolling

使用 DataFrame 调用滚动。

pandas.Series.quantile

Series 的聚合分位数。

pandas.DataFrame.quantile

DataFrame 的聚合分位数。

Examples

>>> s = pd.Series([1, 2, 3, 4])
>>> s.rolling(2).quantile(.4, interpolation='lower')
0    NaN
1    1.0
2    2.0
3    3.0
dtype: float64
>>> s.rolling(2).quantile(.4, interpolation='midpoint')
0    NaN
1    1.5
2    2.5
3    3.5
dtype: float64