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
Asked
Active
Viewed 2.0k times
6
-
You could use numpy.percentile to get quartiles and deciles. http://docs.scipy.org/doc/numpy-dev/reference/generated/numpy.percentile.html – Zero Apr 06 '15 at 13:13
1 Answers
12
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])

Will Da Silva
- 6,386
- 2
- 27
- 52

Zero
- 74,117
- 18
- 147
- 154
-
1Also worth checking out `pandas.qcut`, which will split your array up into whatever quantiles you specify. – mway Apr 20 '15 at 14:58
-
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)) # deciles` – pltrdy Jun 17 '21 at 12:23