This website uses cookies to collect usage information in order to offer a better browsing experience. By browsing this site or by clicking on the "ACCEPT COOKIES" button you accept our Cookie Policy.

# Central Limit Theorem explained in Python (with examples) – Part III Contributor:
QuantInsti
Visit: QuantInsti

See Part I and Part II to get started.

Now we want to see how the sampling distribution looks for this population. We will consider two cases, i.e. with a small sample size (n= 2), and a large sample size (n=500).

First, we will draw 50 random samples from our population of size 2 each. The code to do the same in Python is given below:

# drawing 50 random samples of size 2 from the exponentially distributed population
sample_size = 2
df2 = pd.DataFrame(index= [‘x1’, ‘x2’] )

for i in range(1, 51):
exponential_sample = np.random.exponential((1/rate), sample_size)
col = f’sample {i}’
df2[col] = exponential_sample

# Taking a peek at the samples
df2

2 rows × 50 columns

For each of the 50 samples, we can calculate the sample mean and plot its distribution as follows:

# Calculating sample means and plotting their distribution
df2_sample_means = df2.mean()
sns.distplot(df2_sample_means);

We can observe that even for a small sample size such as 2, the distribution of sample means looks very different from that of the exponential population, and looks more like a poor approximation of a normal distribution, with some positive skew.

Stay tuned for the next installment, in which Ashutosh will repeat the above process, but with a much larger sample size (n=500). 