6

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

1 Answer 1

13

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])
Sign up to request clarification or add additional context in comments.

4 Comments

Also worth checking out pandas.qcut, which will split your array up into whatever quantiles you specify.
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: you're mistaken
example @mway's_comment

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.