How to calculate an Excel BETA.INV in Python

February 6, 2019

Recently I was tasked with coding a complex calculation in Python, where the source was in Excel. They used the BETA.INV function to find theinverse of the beta cumulative probability density function.

Luckily, SciPi also has a beta function where the .PPF is the inverse of .CDF. The first three arguments, probability, alpha and beta are the same, but the in excel you can set the lower and upper bound, where as in Python you can set the location and scale.

If you want to convert the lower and upper bound to location and scale, you need to set the location as the lower bound, and the scale as the (upper bound - lower bound) as explained here.

For example, in excel:

BETA.INV(0.75, 5, 1)

is equal to

>>> beta.ppf(0.75, 5, 1)

and if you add lower (10) and upper (15) bounds in excel:

BETA.INV(0.75, 5, 1, 10, 15)

the python equivalent is:

>>> beta.ppf(0.75, 5, 1, loc=10, scale=15-10)


Written By Dillon