sciPy stats.percentileofscore() | Python
scipy.stats.percentileofscore(a, score, kind='rank')函数帮助我们计算分数相对于分数列表的百分位排名。
假设 x 的百分位数是 60%,这意味着 a 中 80% 的分数低于 x。
Parameters :
arr : [array_like] input array.
score : [int or float] Score compared to the elements in array.
kind : [optional] ‘rank’, ‘weak’, ‘strict’, ‘mean’.
Results : Percentile of the scores relative to the array element.
代码#1:
Python3
# percentileofscore
from scipy import stats
import numpy as np
# 1D array
arr = [20, 2, 7, 1, 7, 7, 34]
print("arr : ", arr)
print ("\nPercentile of 7 : ", stats.percentileofscore(arr, 7))
print ("\nPercentile of 34 : ", stats.percentileofscore(arr, 34))
print ("\nPercentile of 2 : ", stats.percentileofscore(arr, 2))
输出:
arr : [20, 2, 7, 1, 7, 7, 34]
Percetile of 7 : 57.1428571429
Percetile of 34 : 100.0
Percetile of 2 : 28.5714285714