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
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.
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.
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 .
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)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With