Univariate analysis examines one variable at a time — its distribution shape, spread, and any anomalies — before you consider how it relates to anything else. It's the first real analytical step of EDA, after basic quality checks.
Numeric Features — What to Check
import pandas as pd
import matplotlib.pyplot as plt
df["price_lakh"].describe() # count, mean, std, min, 25/50/75%, max
df["price_lakh"].hist(bins=15) # shape of the distribution
plt.show()
df["price_lakh"].plot(kind="box") # spread, quartiles, outliers at a glance
plt.show()
Reading a numeric feature's histogram, you're asking: is it roughly symmetric or skewed? Is it unimodal or does it have multiple peaks? Are there implausible values at the extremes?
Recognizing Distribution Shapes
The shape alone tells you a lot: right-skew usually calls for median imputation/log transform; bimodal often signals two hidden subgroups.
Categorical Features — What to Check
df["city"].value_counts() # raw counts per category
df["city"].value_counts(normalize=True) # proportions instead of counts
df["city"].value_counts().plot(kind="bar") # visual comparison
plt.show()
df["city"].nunique() # cardinality — decides encoding strategy
Worked Example
import pandas as pd
prices = pd.Series([45, 68, 60, 72, 95, 78, 110, 130, 105, 140, 500]) # includes one outlier
print(prices.describe())
# mean is pulled up noticeably by the 500 — compare mean vs the 50% (median) row
print(prices.skew()) # positive value confirms a right-skewed distribution
Expected output: the mean will sit visibly higher than the median in .describe()'s output, and .skew() returns a clearly positive number — both independently confirming the right-skew a histogram would also show visually. See Skewness for the formal definition.
Turning Univariate Findings Into Action
| What You See | What It Suggests |
|---|---|
| Strongly skewed numeric feature | Median imputation over mean; consider a log transform; use robust scaling |
| Bimodal numeric feature | Investigate whether a hidden categorical variable explains the two peaks |
| High-cardinality categorical feature | Avoid one-hot encoding; consider frequency or target encoding |
| Near-constant feature (almost no variance) | Likely low predictive value; candidate for removal |
Practical Use Cases
- Deciding the right imputation strategy per feature based on its distribution shape
- Spotting data entry errors (implausible values sitting far outside a feature's normal range)
- Identifying near-constant or extremely high-cardinality features early, before wasting effort engineering them
Common Mistakes
- Only looking at summary statistics (
.describe()) without ever plotting a histogram — two very differently shaped distributions can share nearly identical mean/std. - Judging skew from
.describe()'s numbers alone instead of also checking.skew()or a visual — mean vs median gives a hint, but isn't as precise.
Interview Relevance
Q: "How would you decide whether to log-transform a numeric feature?" Check its distribution — strong right-skew (long tail toward high values, common in prices/income/counts) is the classic signal that a log transform will make the feature closer to normally distributed, which helps linear models and reduces the influence of extreme values.
Practice Question
A "session_duration" feature has mean=340 seconds but median=180 seconds. What does this gap suggest about the distribution's shape, and what would you check next?