I do a fair bit of data analysis using Python. I find that I often end up repeating the same analysis for different input variables (e.g., looking at GDP and then seeing if the answer changes under GPI) or maybe using a different aggregation technique (e.g., mean vs median).

I was thinking about putting together a python framework to help apply various variations to an analysis but was wondering if there is an existing python library accomplishes this.

  • Try googling “monte carlo simulation python”. Lots of hits.
    – Eric S
    Commented May 18, 2019 at 20:51

2 Answers 2


As in other programming languages, one usually accomplishes such a thing in Python by writing a loop or function. For example, if you have an analysis that involves taking the mean of something with numpy.mean, you can replace np.mean with f and wrap the analysis code in a new function that has f as a parameter.


The general term for what you are looking for is Monte Carlo simulations. Although I don't have any personal experience with it, there is a Monte Carlo feature in the Pandas library. In addition, I found pyhmc, pyMC and pyMC3 (which looks like the most up to date).

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.