gpt4 book ai didi

pandas - pandas 使用哪种方法计算百分位数?

转载 作者:行者123 更新时间:2023-12-04 01:49:05 27 4
gpt4 key购买 nike

我试图理解 pandas 中的下/上百分位数计算,但有点困惑。这是它的示例代码和输出。

test = pd.Series([7, 15, 36, 39, 40, 41])
test.describe()

输出:

enter image description here

我只对 25%、75% 的百分位数感兴趣。请问pandas是用什么方法计算的?

引用https://en.wikipedia.org/wiki/Quartile文章,结果不同如下:

enter image description here

那么pandas用什么统计/数学方法来计算百分位数呢?

最佳答案

正如我在评论中提到的,我终于弄清楚了它是如何工作的,方法是按照@Abdou 的建议使用quantile 函数尝试from pandas.core.algorithms import quantile

我不太好只通过打字来解释它,因此我只会在给定的例子中做 25% 和 75% 的例子。这是简短的(可能很差)解释:

对于示例列表 [7, 15, 36, 39, 40, 41] 分位数如下:

7 -> 0%

15 -> 20%

36 -> 40%

39 -> 60%

40 -> 80%

41 -> 100%

因为我们要找到 25% 的百分位数,它会在 15 和 36 之间,而且,它是 20% + 5% = 15 + (36-15)/4 = 15 + 5.25 = 20.25。

(36-15)/4是用的,因为15和36的距离是40% - 20% = 20%,所以我们除以4得到5%。

同样的方法我们可以找到 75%。

60% + 15% = 39 + 3*(40-39)/4 = 39.75

就是这样。我真的很抱歉解释不当

注意:感谢@shin 在评论中提到的更正。

关于pandas - pandas 使用哪种方法计算百分位数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41744275/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com