Contents
Understanding Data Distributions
A distribution describes how values are spread across a variable. Understanding the distribution helps identify typical values, skewness, gaps, and possible outliers.
Creating a Histogram
A histogram groups numerical values into intervals called bins. It helps reveal whether values are concentrated in certain ranges.
import matplotlib.pyplot as plt
sales = [12000, 15000, 18000, 22000, 25000,
17000, 19000, 21000, 28000, 35000]
plt.hist(sales, bins=5, edgecolor="black")
plt.xlabel("Sales")
plt.ylabel("Frequency")
plt.title("Distribution of Sales")
plt.show()
A histogram can reveal whether sales values are concentrated around a particular range or spread across a wider interval. The appearance depends partly on the selected number of bins, so avoid drawing conclusions from a single arbitrary setting.
Measuring Skewness
Skewness describes the asymmetry of a distribution.
import pandas as pd
sales = pd.Series([
12000, 14000, 15000, 16000,
18000, 20000, 22000, 75000
])
print("Mean:", sales.mean())
print("Median:", sales.median())
print("Skewness:", sales.skew())
A positive skew often indicates a longer tail toward higher values, while a negative skew indicates a longer tail toward lower values. A skewness value near zero does not necessarily mean that a distribution is normal.
Comparing the mean and median, examining histograms, and investigating extreme observations together provides a more complete picture of the distribution.
Using a Box Plot
A box plot displays the median, quartiles, and potential outliers.
plt.boxplot(sales)
plt.ylabel("Sales")
plt.title("Sales Distribution")
plt.show()
Box plots are particularly useful for comparing distributions across groups. Points outside the whiskers are potential outliers under the plotting convention, not automatically errors that must be removed.
Python for Data Science
Vishalini A








