當前位置: 首頁>>編程示例 >>用法及示例精選 >>正文


Python pandas.Series.quantile用法及代碼示例

用法:

Series.quantile(q=0.5, interpolation='linear')

返回給定分位數的值。

參數

qfloat 或 array-like,默認 0.5(50% 分位數)

要計算的分位數,可以在範圍內:0 <= q <= 1。

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

當所需的分位數位於兩個數據點 ij 之間時,此可選參數指定要使用的插值方法:

  • 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.

返回

浮點數或係列

如果q 是一個數組,則將返回一個係列,其中索引為q,值是分位數,否則將返回一個浮點數。

例子

>>> s = pd.Series([1, 2, 3, 4])
>>> s.quantile(.5)
2.5
>>> s.quantile([.25, .5, .75])
0.25    1.75
0.50    2.50
0.75    3.25
dtype:float64

相關用法


注:本文由純淨天空篩選整理自pandas.pydata.org大神的英文原創作品 pandas.Series.quantile。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。