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
1 Answer
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])
4 Comments
mway
Also worth checking out
pandas.qcut, which will split your array up into whatever quantiles you specify.pltrdy
That seems incorrect to me. There should be 3 quartiles (i.e. 25%, 50%, 75%) and 9 deciles (i.e. 10%, 20%, ..., 90%). Here the first value of both is the minimum because you start
np.arange at 0 use instead: np.percentile(var, np.arange(25, 100, 25)) # quartiles and np.percentile(var, np.arange(10, 100, 10)) # decilesJeeyCi
@ pltrdy: you're mistaken