Sitemap
Arjun Sharma

Arjun Sharma

Normal Distribution in Python

4 min readMay 3, 2019

What is a Normal Distribution?
A normal distribution, sometimes called the bell curve, is a distribution that occurs naturally in many situations.

For example:
The bell curve is seen in many situations like
· Heights of people
· size of things produced by machines
· errors in measurements
· blood pressure
· marks on a test

The “Bell Curve” is a Normal Distribution and the yellow histogram shows some data that follows it closely, but not perfectly (which is usual).

Properties of Normal Distribution:
The mean, mode and median are all equal.
The curve is symmetric at the center (i.e. around the mean, μ).
Exactly half of the values are to the left of center and exactly half the values are to the right.

Standard Deviation
Standard deviation is a number used to tell how measurements for a group are spread out from the average (mean) or expected value.

When we calculate the standard deviation, generally it is found that
· 68% of data falls within one standard deviation of mean.

· 95% of data falls within two standard deviations of mean.

· 99.7% of data falls within three standard deviations of mean.

Let’s understand with an example:

A survey of daily travel time had these results (in minutes):
26, 33, 65, 28, 34, 55, 25, 44, 50, 36, 26, 37, 43, 62, 35, 38, 45, 32, 28, 34

The Mean is 38.8 minutes, and the Standard Deviation is 11.4 minutes
Calculation shown in Excel below:

Formula for calculating Mean in Excel:
=AVERAGE(A2:A21)

Formula for calculating Standard Deviation in Excel:
=STDEVP(A2:A21)

Get Arjun Sharma’s stories in your inbox

Join Medium for free to get updates from this writer.

Formula for calculating Normal Distribution in Excel:
=NORM.DIST(A2,$C$2,$D$2,FALSE)

Now as we have done with the calculations, we will select all the values of Time and Normal Distribution and put them into a chart (go to insert-> select scatter->drag and drop Scatter with Smooth Lines) in Excel as shown below

It is showing some weird shape by looking the output of the chart. We want the bell curved shape in the chart so what’s the solution for it?
We can sort the Time and Normal Distribution values from smallest to largest and then see the changes occurs in the chart as shown below

Now the values will get sorted and let’s see if we get the bell curved shape in chart or not as shown below

As we can see above, we have not got proper bell curved shape but it looks good as it was before sorting the values.

Now what if we want to see the values in chart?
For that we need to go to insert-> select scatter->drag and drop Scatter with Smooth Lines and Markers as shown below

As we can see above, I have kept my mouse at point 38 so it is showing me the value of Normal Distribution as well.

Now let’s do the same example in Python
For that i have written a code in PyCharm as shown below

In above program ‘mu’ is the Mean and sigma is ‘Standard Deviation’

Run the Python file and see the output

As you can see above i have not given any data in my program, instead i just gave Mean value as 38.8 and Standard Deviation value as 11.4 and got the results.

Now we can see a perfect bell curved shape in the output.
The Time values is in x-axis and Normal Distribution values is in y-axis, so when i kept my mouse in x=38(almost) it is showing me the proper Normal Distribution value of 38 in y-axis.

See down below video teaching on Data Science: -

--

--