sciPy stats.percentileofscore() | Python

scipy.stats.percentileofscore(a, score, kind='rank') function helps us to calculate percentile rank of a score relative to a list of scores.

Suppose percentile of x is 60% that means that 80% of the scores in a are below 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.

Code #1:

filter_none

edit
close

play_arrow

link
brightness_4
code

# percentileofscore
from scipy import stats
import numpy as np 
  
# 1D array  
arr = [20, 2, 7, 1, 7, 7, 34
print("arr : ", arr)  
  
print ("\nPercetile of 7  : ", stats.percentileofscore(arr, 7))
  
print ("\nPercetile of 34 : ", stats.percentileofscore(arr, 34))
  
print ("\nPercetile of 2  : ", stats.percentileofscore(arr, 2))

chevron_right


Output:

arr :  [20, 2, 7, 1, 7, 7, 34]

Percetile of 7  :  57.1428571429

Percetile of 34 :  100.0

Percetile of 2  :  28.5714285714
My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.