Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

what's the inverse of the quantile function on a pandas Series?

The quantile functions gives us the quantile of a given pandas series s,

E.g.

s.quantile(0.9) is 4.2

Is there the inverse function (i.e. cumulative distribution) which finds the value x such that

s.quantile(x)=4

Thanks

like image 429
Mannaggia Avatar asked Oct 21 '14 14:10

Mannaggia


People also ask

What is the inverse of a quantile?

The quantile function, Q, of a probability distribution is the inverse of its cumulative distribution function F. The derivative of the quantile function, namely the quantile density function, is yet another way of prescribing a probability distribution.

How do you find the quantile value of a panda?

Pandas DataFrame quantile() MethodThe quantile() method calculates the quantile of the values in a given axis. Default axis is row. By specifying the column axis ( axis='columns' ), the quantile() method calculates the quantile column-wise and returns the mean value for each row.

What is the quantile function in Python?

In Python, the numpy. quantile() function takes an array and a number say q between 0 and 1. It returns the value at the q th quantile. For example, numpy. quantile(data, 0.25) returns the value at the first quartile of the dataset data .


1 Answers

I had the same question as you did! I found an easy way of getting the inverse of quantile using scipy.

#libs required from scipy import stats import pandas as pd import numpy as np  #generate ramdom data with same seed (to be reproducible) np.random.seed(seed=1) df = pd.DataFrame(np.random.uniform(0,1,(10)), columns=['a'])  #quantile function x = df.quantile(0.5)[0]  #inverse of quantile stats.percentileofscore(df['a'],x) 
like image 129
fernandosjp Avatar answered Oct 04 '22 16:10

fernandosjp