Monte Carlo Simulations in Python
Izzy Weber
Curriculum Manager, DataCamp
Bell-shaped and centered at the mean (or loc); width defined by standard deviation (or scale)
The heights of American adult males are normally distributed:
Normally distributed US adult male heights; mean = 177 cm; standard deviation = 8 cm
What's the percentage of people with a height either above 190 or below 165 cm?
heights = st.norm.rvs(loc=177, scale=8, size=10000)
qualified = (heights < 165) | (heights > 190)
print(np.sum(qualified) * 100/10000)
12.28
heights_dict = {"heights":heights}
sns.histplot(x="heights", data=heights_dict)
plt.axvline(x=165, color="red")
plt.axvline(x=190, color="red")
st.uniform
)st.expon
)Monte Carlo Simulations in Python