I'd like to pass weights to scipy.stats.percentileofscore
. For example:
from scipy import stats
a = [1, 2, 3, 4]
val = 3
stats.percentileofscore(a, val)
Returns 75, as 75% of the values in a
lie at or below the val
3.
I'd like to add weights, for example:
weights = [2, 2, 3, 3]
weightedpercentileofscore(a, val, weights)
Should return 70, since (2 + 2 + 3) / (2 + 2 + 3 + 3) = 7 / 10 of the weights fall at or below 3.
This should also work for decimal weights and large weights, so just expanding the arrays isn't ideal.
Weighted percentile using numpy is relevant, but calculates percentiles (e.g. asking for the 10th percentile value) rather than the specific percentile for a value.