集中趋势指标特点
什么是集中趋势指标
集中趋势之平均值
集中趋势之中位数
集中趋势之众数
案例
问题
比较两组人员的薪资水平。
计算这两组薪酬数据的平均值、中位数、众数,并根据平均值、中位数和众数来判断哪一组的薪酬水平更高,原因是什么?
编码
import numpy as np
from decimal import Decimal
salary_1 = [8600, 8700, 9500, 10400, 11000, 11500, 12500]
salary_2 = [3900, 4500, 7300, 9500, 11500, 14500, 21000]
mean_salary_1 = np.mean(salary_1)
mean_salary_2 = np.mean(salary_2)
median_salary_1 = np.median(salary_1)
median_salary_2 = np.median(salary_2)
mode_salary_1 = np.argmax(np.bincount(salary_1))
mode_salary_2 = np.argmax(np.bincount(salary_2))
print('mean_salary_1 %.2f' % mean_salary_1)
print('mean_salary_2 %.2f \n' % mean_salary_2)
print('median_salary_1 %.2f' % median_salary_1)
print('median_salary_2 %.2f \n' % median_salary_2)
print('mode_salary_1 %.2f' % mode_salary_1)
print('mode_salary_2 %.2f' % mode_salary_2)
输出
mean_salary_1 10314.29
mean_salary_2 10314.29
median_salary_1 10400.00
median_salary_2 9500.00
mode_salary_1 8600.00
mode_salary_2 3900.00
结论
结论:组1的薪资水平高于组2