Sampling, Population, and the Central Limit Theorem
A population includes all individuals or observations relevant to a study. A sample is a subset selected from that population.
Analyzing a sample is often more practical than examining an entire population. However, conclusions based on samples depend on how the observations are selected and how representative the sample is.
Selecting a Random Sample
Pandas allows you to select a sample of rows from a DataFrame.
import pandas as pd
df = pd.DataFrame({
"Customer_ID": range(1, 101),
"Spending": [1000 + i * 50 for i in range(100)]
})
sample = df.sample(n=10, random_state=42)
print(sample)
The n parameter specifies the number of observations, and random_state makes the selection reproducible.
A random sample is useful for exploration and testing. In practical studies, consider whether the sampling method introduces bias, especially when certain customer groups are underrepresented.
Understanding Sampling Error
Different samples from the same population can produce different sample means. This variation is known as sampling variability.
For a sample mean, the standard error is commonly estimated by:
[
SE=\frac{s}{\sqrt{n}}
]
Here, (s) is the sample standard deviation and (n) is the sample size.
import numpy as np
sample_values = np.array([42, 45, 48, 50, 55, 57, 60])
standard_error = np.std(sample_values, ddof=1) / np.sqrt(len(sample_values))
print("Standard error:", standard_error)
A larger sample generally produces a smaller standard error when other conditions remain comparable. However, increasing sample size does not automatically eliminate bias caused by poor sampling methods.
The Central Limit Theorem
The Central Limit Theorem states, under appropriate conditions, that the sampling distribution of the sample mean approaches a normal distribution as the sample size grows, even when the underlying population is not normally distributed.
This principle supports many statistical procedures, including confidence intervals and hypothesis tests.
The required sample size depends on the population distribution and the assumptions of the analysis. A larger sample is not a universal guarantee that every statistical method will be valid.
Python for Data Science
Vishalini A








