Wednesday, July 3, 2024
HomeLanguagesPythonsciPy stats.percentileofscore() | Python

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: 
 

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))


Output:

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

Percentile of 7  :  57.1428571429

Percentile of 34 :  100.0

Percentile of 2  :  28.5714285714
Shaida Kate Naidoo
am passionate about learning the latest technologies available to developers in either a Front End or Back End capacity. I enjoy creating applications that are well designed and responsive, in addition to being user friendly. I thrive in fast paced environments. With a diverse educational and work experience background, I excel at collaborating with teams both local and international. A versatile developer with interests in Software Development and Software Engineering. I consider myself to be adaptable and a self motivated learner. I am interested in new programming technologies, and continuous self improvement.
RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments