简体   繁体   English

Pandas.. 分位数 function 需要排序数据来计算百分位数吗?

[英]Pandas.. does quantile function need sorted data to calculate percentiles?

I'm using Pandas to clean up some data and do basic statistics.我正在使用 Pandas 来清理一些数据并进行基本统计。 I am wondering if quantile() does sort the values before the calculation or i must do the sorting beforehand?我想知道quantile()是否在计算之前对值进行排序,或者我必须事先进行排序?

For example, here I'm trying to get the 50th percentile of the number of workers in each company例如,在这里我试图获得每家公司员工人数的第 50 个百分位

Percentile50th = Y2015_df.groupby (["company"])["worker"].quantile(0.50)

I'm asking because when I was verifying the values I got with the results in MS Excel, I discovered that Median function requires the data to be sorted in order to get the right median.我之所以问,是因为当我用 MS Excel 中的结果验证我得到的值时,我发现中位数 function 需要对数据进行排序以获得正确的中位数。 But I'm not sure if its the case in Pandas.但我不确定 Pandas 是否属于这种情况。

You do not need to sort.你不需要排序。 See the link in my previous comment.请参阅我之前评论中的链接。 Example 例子

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM