Pandas如何计算分位数?

时间:2016-02-23 18:14:18

标签: python pandas

我有以下简单的数据框:

> df = pd.DataFrame({'calc_value': [0, 0.081928, 0.94444]})
> df
   calc_value
0    0.000000
1    0.081928
2    0.944440

为什么df.quantile将第90个百分位数计算为0.7719376

> df.quantile(0.9)['calc_value']`
0.7719376

根据我的计算,它应该是0.69,通过(0.944444-0.081928)*((90-50)/(100-50))

1 个答案:

答案 0 :(得分:2)

嗯,在0.5 ...... 1.0的范围内每0.1的步数等于(0.94444-0.081928)/ 5并且等于0.1725024

So 50q is 0.081928
60q is 0.081928+0.1725024=0.25443
70q is 0.081928+2*0.1725024=0.426933
80q is 0.081928+3*0.1725024=0.599435
90q is 0.081928+4*0.1725024=0.771938
100q is 0.081928+5*0.1725024=0.94444