Solving for quartile and decile using Python

2024/11/17 10:05:12

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

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])
https://en.xdnf.cn/q/71565.html

Related Q&A

Predicted values of each fold in K-Fold Cross Validation in sklearn

I have performed 10-fold cross validation on a dataset that I have using python sklearn, result = cross_val_score(best_svr, X, y, cv=10, scoring=r2) print(result.mean())I have been able to get the mean…

What does the comma mean in Pythons unpack?

We can simply use: crc = struct.unpack(>i, data)why do people write it like this: (crc,) = struct.unpack(>i, data)What does the comma mean?

How do I manually add more cookies to a session which already has cookies set in mechanize?

I have a python script which scrapes a page and receives a cookie. I want to append another cookie to the existing cookies that are being send to the server. So that on the next request I have the cook…

python generators time complexity confusion

I have been reading about keyword yield and generators in python and I want to know if I have understood it right it terms of time complexity.Here is my generator function to get factors:def calc_facto…

Python: Find Amount of Handwriting in Video

Do you know of an algorithm that can see that there is handwriting on an image? I am not interested in knowing what the handwriting says, but only that there is one present? I have a video of someone…

Include nonce and block count in PyCrypto AES MODE_CTR

Some background information, you can skip this part for the actual questionthis is my third question about this topic here at stackoverflow. To be complete, these are the other questions AES with crypt…

Why is pandas.series.map so shockingly slow?

Some days I just hate using middleware. Take this for example: Id like to have a lookup table that maps values from a set of inputs (domain) values, to outputs (range) values. The mapping is unique. A …

Viewset create custom assign value in Django Rest Framework

Would like to set a CustomUsers username by using the input email, but where to do the custom assigning, in view? At the same time it receiving a file as well.Models.pyclass CustomUser(AbstractUser):a…

Remove a relation many-to-many (association object) on Sqlalchemy

Im stuck with a SqlAlchemy problem.I just want to delete an relation. This relation is made by an association object.modelsclass User(db.Model, UserMixin):id = db.Column(db.Integer, pr…

Spark Dataframes: Skewed Partition after Join

Ive two dataframes, df1 with 22 million records and df2 with 2 million records. Im doing the right join on email_address as a key. test_join = df2.join(df1, "email_address", how = right).cach…