【问题标题】:How to determine the quartiles and deciles from a given data set如何从给定的数据集中确定四分位数和十分位数
【发布时间】:2022-10-19 02:45:29
【问题描述】:

我正在编写一个程序来执行两个步骤。

步骤 1. 计算 Q1、Q2、Q3

步骤 2. 计算 D1、D2、D3、D4、D4、D5、D6、D7、D8、D9

我写的程序是这样构造的:

# Author: Evan Gertis
# Date 10/08
# program: quartiles & deciles

wages       = [250.00,259.99,260.00,269.99,270.00,279.99,280.00,289.99,290.00,299.99,300.00,309.99,310.00,319.99]
n_employees = [8,10,16,14,10,5,2]
total       = 65

def quartile(n,w,employees):
    return wages[2*n-1] + total/n - n_employees[2*n-1]/n_employees[2*n]*10

# Step 1. calculate Q1, Q2, Q3
print(quartile(2,wages,n_employees))

# Step 2. calculate D1, D2, D3, D4, D4, D5, D6, D7, D8, D9

数据集为

如果有人能解释下面显示的十分位数计算,我将不胜感激。

我想用 numpy 来执行这个操作。任何帮助将不胜感激。谢谢你。

【问题讨论】:

    标签: python data-science


    【解决方案1】:

    您不能使用范围作为输入来明确计算统计数据。

    使用较低的 bin 端(您可以使用您喜欢的最大值或平均值)和numpy.quantile

    np.quantile(np.repeat(wages[::2], n_employees), q=[0.25, .5, .75])
    

    输出:array([260., 270., 290.])

    使用 bin 的平均值:

    wages = np.array(wages)
    
    np.quantile(np.repeat((wages[::2]+wages[::2])/2, n_employees), q=[0.25, .5, .75])
    

    输出:array([260., 270., 290.])

    对于十分位数,对 q=np.arange(.1, 1, .1) 执行相同操作

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-09-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多