【发布时间】:2019-12-05 19:57:27
【问题描述】:
我想在这样的多个列表中计算 95 个百分位数:
import numpy as np
list_a = [0, 5, 10, 2, 3, 5]
list_b = [0, 0, 6, 5, 4, 4]
list_t = []
list_t.extend(list_a)
list_t.extend(list_b)
list_t_pc = np.percentile(list_t, 95)
print('percentile of list total percentile : '+str(list_t_pc))
输出:
percentile of list total : 7.799999999999997
但就我而言,我每天都在收集数据,我无法将所有值保存在列表中。我可以按天保存一个值(例如平均值、最大值或百分比)。所以要得到最接近的 95% 的值:
import numpy as np
day_1 = [0, 5, 10, 2, 3, 5]
day_2 = [0, 0, 6, 5, 4, 4]
day_1_pc = np.percentile(day_1, 95)
day_2_pc = np.percentile(day_2, 95)
list_pc = [day_1_pc, day_2_pc]
print('percentile of percentile : '+str(np.percentile(list_pc, 95)))
输出:
percentile of percentile : 8.6
有没有办法计算出更接近的值?
【问题讨论】:
-
如果我正确理解您的问题,请在计算百分位数之前加入列表。
np.percentile(list_a + list_b,95) -
我不明白你的问题。请改写它以使其更易于解析,并制定一个更准确的问题,即您想要计算什么。
-
我编辑的帖子可能更清晰
-
为什么不能保存之前的结果?你不能将它存储在文件或类似的东西中吗?以及如何只保存前几天的单个值?
-
以前的结果保存在数据库中,但我受到条目大小的限制。所以我只保存了几个值,以免达到存储限制。
标签: python python-3.6 percentile