Exploratory Data Analysis
After this lesson, you will be able to:
- Use charts (histograms, scatter plots, box plots) to spot patterns, relationships, and weird outliers in your data
- Calculate basic stats (mean, median, standard deviation, correlation) and know when each one can trick you
- Follow a step-by-step 'explore first, model later' workflow on any new dataset to catch problems early and find useful patterns
- Use automated EDA tools like pandas-profiling (ydata-profiling) to generate comprehensive distribution checks, correlation matrices, and data quality reports in seconds
Before you start
Don't worry if all the different charts and stats feel overwhelming — you only need a few of them for most projects, and you will build the instinct with practice!
#The Detective Mindset
#The Summary Statistics Toolkit
#Measures of Central Tendency
The first question about any numeric variable: where is the center?
When to use which
- Mean: When data is roughly symmetric and outlier-free. Good for: test scores, temperatures.
- Median: When data is skewed or has outliers. Good for: income, house prices, response times.
- Mode: The most frequent value. Useful for categorical data or multi-modal distributions.
#Measures of Spread
The center alone is not enough. Two datasets can have identical means but wildly different spreads.
This lesson divides by n, which describes the data in hand. For estimating the spread of a wider population you divide by n - 1, and why that is exactly right is derived in Descriptive Statistics & Distributions (Why dividing by n is too small and n - 1 is exactly right).
#Correlation: Are Two Variables Related?
Why r always lies between -1 and +1, and why a perfect U-shaped curve can have r = 0, are derived in Correlation: Pearson, Spearman & Multicollinearity, so they are not derived again here.
Try it! Open the Python REPL and type these lines yourself. Generate a random dataset withimport numpy as np; x = np.random.randn(100); y = x**2and computenp.corrcoef(x, y)[0,1]— you will see correlation near zero even though y depends entirely on x!
#Visual EDA: The Power of Plots
#Histograms: Shape of a Distribution
A histogram bins continuous data into intervals and shows frequency. It reveals:
- Skewness: Is the distribution symmetric, left-skewed, or right-skewed?
- Modality: One peak (unimodal), two peaks (bimodal), or more?
- Outliers: Isolated bars far from the main distribution?
- Gaps: Missing ranges that suggest data collection issues?
A dataset of employee salaries has a mean of $95,000 and a median of $62,000. What does this tell you about the distribution?
#Scatter Plots: Relationships Between Variables
A scatter plot shows the relationship between two numeric variables. Each point is one observation. Look for:
- Linear trends: Points forming a line (positive or negative slope)
- Nonlinear patterns: Curves, clusters, fan shapes
- Outliers: Points far from the main cloud
- Heteroscedasticity: Spread that changes along the x-axis (fan shape)
#Box Plots: Distribution Summary in One Glance
A box plot compresses an entire distribution into five numbers:
- Minimum (excluding outliers)
- Q1 (25th percentile)
- Median (50th percentile)
- Q3 (75th percentile)
- Maximum (excluding outliers)
Points beyond 1.5 * IQR from Q1 or Q3 are plotted individually as potential outliers.
#The EDA Workflow
A systematic EDA follows these steps:
#Step 1: First Look
Check shape (rows x columns), data types, and the first few rows. How many numeric vs categorical columns? Any obvious issues at a glance?
df.shape # (10000, 25)
df.dtypes # numeric, object, datetime
df.head() # first 5 rows#Step 2: Missing Values
Count nulls per column. Are missing values random or systematic? A column that is 90% null is probably useless. A column that is null only for one category might indicate a data collection issue.
df.isnull().sum() # nulls per column
df.isnull().mean() * 100 # percent null per column#Step 3: Univariate Analysis
Examine each variable individually. Histograms for numeric columns. Bar charts for categorical columns. Look for unexpected distributions, impossible values, and heavy tails.
#Step 4: Bivariate Analysis
Examine relationships between pairs of variables. Scatter plots for numeric-numeric. Box plots for numeric-categorical. Heatmaps for correlation matrices. Look for strong correlations, nonlinear relationships, and interaction effects.
#Step 5: Multivariate Analysis
Look at three or more variables simultaneously. Color scatter plots by a third variable. Use pair plots for all combinations. Detect confounders — variables that create spurious correlations between others.
#Step 6: Document Findings
Write down what you learned. Which features seem predictive? Which have quality issues? What transformations are needed? This document becomes the blueprint for feature engineering.
#Anscombe's Quartet: Why You Must Plot
#Try It Yourself
Tests: Verify summary stats are computed correctly. Identify at least 3 data quality issues. Compute correlation between age and income.
#The Five-Number Summary and Beyond
The five-number summary (min, Q1, median, Q3, max) is the foundation of the box plot. But for ML, you often need more:
- Skewness: Measures asymmetry. Zero for symmetric distributions. Positive means right-tailed.
- Kurtosis: Measures tail heaviness. High kurtosis means more outliers than a normal distribution.
- Cardinality: For categorical variables, how many unique values? A column with 10,000 unique values out of 10,000 rows is likely an ID, not a useful feature.
- Null rate: What percentage of values are missing? Per column and per row.
Why skewness is 0 for symmetric data and why its sign points at the longer tail is derived in Quantiles, Shape & Reading Real Data. The minus 3 in the kurtosis formula is derived below.
#EDA for Different Data Types
#Tabular Data
Standard approach: summary stats, histograms, scatter plots, correlation matrices. This is the "classic" EDA.
#Text Data
Word frequency distributions, document length distributions, vocabulary size, language detection, n-gram analysis. Look for: encoding issues, mixed languages, extremely short or long documents.
#Image Data
Resolution distribution, channel statistics (mean pixel values per channel), class balance for labeled datasets. Look for: corrupted images, duplicates (by hash), unexpected resolutions.
#Time Series Data
Trend, seasonality, autocorrelation. Plot the raw series first. Decompose into trend + seasonal + residual. Look for: gaps in timestamps, irregular sampling, regime changes.
#Key Takeaways
- Always plot your data before modeling. Anscombe's Quartet proves that summary statistics alone can be deeply misleading; four datasets with identical means, variances, and correlations look completely different when visualized
- Choose the right central tendency measure. Use the mean for symmetric data and the median for skewed data with outliers; when mean greatly exceeds median, the distribution is right-skewed
- Correlation of zero does not mean no relationship. Pearson's r only measures linear association; a perfect U-shaped or circular relationship produces r near zero, so always combine statistics with scatter plots
- Follow a systematic EDA workflow. Start with shape and types, check missing values, analyze univariate distributions, examine bivariate relationships, then document findings before building any model
- EDA is continuous, not one-time. In production systems, automated EDA tools and feature stores monitor distribution drift and quality issues on every new data batch
#Quick Check
Why might the mean be misleading for income data?
Modern EDA workflows in 2026 lean on ydata-profiling, Sweetviz and Dataprep for one-line dataset summaries, then Polars or DuckDB for fast hypothesis-checking on data that doesn't fit in pandas memory. The instinct to look at your data for an hour before modeling has not changed; the tools just got faster.