Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Solving for quartile and decile using Python

Is there a library for Python 2.7 that can solve quartiles and deciles. It seems that numpy doesn't have any functions for it. Can you give me a link if there are any. Thanks in advance! :D

like image 284
OrdinaryProgrammer Avatar asked Apr 06 '15 13:04

OrdinaryProgrammer


1 Answers

Using np.percentile, you could try something like

>>> import numpy as np
>>> var = np.array([10, 7, 4, 3, 2, 1]) # input array
>>> np.percentile(var, np.arange(25, 100, 25)) # quartiles
array([2.25, 3.5 , 6.25])
>>> np.percentile(var, np.arange(10, 100, 10)) # deciles
array([1.5,  2. ,  2.5,  3. ,  3.5,  4. ,  5.5,  7. ,  8.5])
like image 93
Zero Avatar answered Sep 19 '22 09:09

Zero