EDA
Beginner 13 min read EDA

Univariate Analysis

Get to know each feature alone

One variable at a time: histograms, KDEs, value counts and summary stats characterize each feature's distribution, scale and sparsity before any relationship is examined.

histogramKDEvalue_countsdistributionskewmode
Prerequisites: EDA Introduction
Before we start

What you will learn

  • Use histograms/KDE and value_counts to read shape
  • Detect skew, modes and sparsity
  • Decide per-column encodings from distributions
Introduction

What is this?

Univariate analysis examines one column at a time. For numerics: histogram/KDE shapes, skew, modes, ranges. For categoricals: value_counts cardinality and balance. Outputs drive real decisions — which columns to log-transform, which to treat as categorical, which are sparse enough to re-bucket, and which predictors are constant (and useless).

Motivation

Why do you need it?

  • Distribution knowledge dictates preprocessing: log for right-skew, one-hot for low-cardinality categories.
  • A column with one dominant value added to a distance model just adds noise.
  • Encoding, imputation and scaling choices are univariate facts.
  • Half of 'model didn't work' is a feature that was never profiled.
Think about it

Mental model

Imagine

Meeting each team member before running a project

Think of

Univariate analysis of each column

You want to know each person's proficiency (distribution), talkativeness (mode), and outlier behavior (tails) before organizing them into teams (relationships). One-on-ones precede team dynamics.

Mechanics

How it works

  • Numerics: df['x'].hist(bins=50) + KDE reveal shape; .skew() quantifies it.
  • Categoricals: df['x'].value_counts(normalize=True) gives balance and cardinality.
  • Sparsity: fraction of zeros/short codes via value_counts — 'sparse categories' get collapsed.
  • Modes: multiple peaks suggest mixed populations (two segments in one column).
  • Constant columns: nunique() == 1 → no predictive information.

Univariate decision flow.

Column
Numeric
Categorical
Shape verdict
Decision
Hands-on

Examples

Profile one numeric + one categorical

Profile one numeric + one categorical
import pandas as pd, numpy as np
rng = np.random.default_rng(1)
x = np.exp(rng.normal(2, .8, 5000))
y = rng.choice(['a','b','c'], 5000, p=[.85,.1,.05])
print(pd.Series(x).describe(percentiles=[.5,.9,.99]).round(2))
print(pd.Series(y).value_counts(normalize=True))

The numeric shows right tail (p99 far from p50) — a log-transform candidate. The categorical is 85/10/5 — a clearly imbalanced category that may need collapsing or sampling attention.

Real world

In production

  • A fraud feature engineer logs revenue columns after seeing skew in univariate profiles.
  • A churn model drops a 'user_id' column based on nunique()==shape — a constant/key leak.
  • A recommender bins a long-tail categorical by frequency after value_counts shows a 1%-covered tier set.
Guidelines

Best practices

  • Profile every candidate feature; document what you saw.
  • Check zeros separately from 'real' small values — zeros often encode something.
  • For categoricals, record cardinality BEFORE deciding encodings.
Watch out

Common mistakes

  • Fitting scaling on raw skewed columns — the mean/std then lie.
  • One-hot encoding a 2000-level categorical without a frequency cut.
  • Missing a bimodal column that splits two populations.
When things break

Debugging tips

  • value_counts(normalize=True).head() shows whether a tiny category is noise or a real group.
  • If skew() ≈ 0 but the histogram has two peaks → bimodal check, not 'symmetric'.
  • A log transform of a column with zeros fails — inspect zeros first.
Interviews

Interview checkpoint

Practice

Hands-on lab

Profile Every Column
25 min · beginner
In progress
Objectives
  • Profile numerics with describe + KDE
  • Profile categoricals with value_counts
  • Make per-column preprocessing decisions

Profile Every Column

25 min · beginner

0/5 steps
0%
sandbox · Linux sandbox
$
Try these commands
Test yourself

Quick quiz

0/2
1

A histogram with two clear peaks indicates:

2

A column with a single unique value can still be a strong predictor.

Go deeper

Official documentation