Automating EDA: From Raw CSV to Insights in 15 Minutes
Using ydata-profiling, Sweetviz, and custom Pandas pipelines to automate exploratory data analysis. Built during the ACM Data Science SIG weekend workshop.
Exploratory data analysis is the part of a project that everyone rushes and
then pays for later. The usual pattern: df.head(), df.describe(), a couple
of histograms, and straight into modelling — followed three days later by the
discovery that a column had 40% missing values all along.
Automating the boring 80% leaves time for the interesting 20%.
Start with a profile, not a plot
ydata-profiling produces a full report in one call:
import pandas as pd
from ydata_profiling import ProfileReport
df = pd.read_csv("events.csv")
profile = ProfileReport(
df,
title="Events EDA",
explorative=True,
# Correlations are O(n²) in columns — skip them on wide frames
correlations={"auto": {"calculate": df.shape[1] < 50}},
)
profile.to_file("eda.html")
What you get for free: per-column distributions, missing-value patterns, cardinality, duplicate rows, and correlation matrices. On a 50-column dataset that is a couple of hours of manual work.
The catch: on anything above ~100k rows it gets slow. Profile a sample.
sample = df.sample(n=min(50_000, len(df)), random_state=42)
The checks that catch real problems
Automated reports tell you what the data looks like. These are the questions that tell you whether it is usable:
def sanity_report(df: pd.DataFrame) -> pd.DataFrame:
return pd.DataFrame({
"dtype": df.dtypes,
"missing_pct": (df.isna().mean() * 100).round(2),
"unique": df.nunique(),
"unique_pct": (df.nunique() / len(df) * 100).round(2),
"zeros_pct": ((df == 0).sum() / len(df) * 100).round(2),
"sample": df.iloc[0],
}).sort_values("missing_pct", ascending=False)
Read it top to bottom looking for:
missing_pctabove 50% — the column is probably a lost cause, or missing is the signalunique_pctnear 100 on a non-ID column — likely a free-text field masquerading as a categoryuniqueof 1 — constant column, drop itzeros_pctunexpectedly high — often missing values that were filled with 0 upstream
That last one has burned more projects than any other. A zero temperature and a missing temperature are not the same fact.
Missingness is a pattern, not noise
Whether values are missing at random changes what you are allowed to do about them:
import missingno as msno
msno.matrix(df) # where the gaps are, row by row
msno.heatmap(df) # do columns go missing together?
If two columns are always missing together, they likely share an upstream source that failed. Imputing them independently invents a combination that never occurs in reality.
Comparing train and test
Sweetviz is worth it for exactly one thing — comparing two frames column by column:
import sweetviz as sv
report = sv.compare([train, "Train"], [test, "Test"], target_feat="attended")
report.show_html("compare.html")
Distribution drift between train and test is the reason for a great many "my model scored 0.94 in validation and 0.61 in production" stories.
Make it a function you rerun
The point of automating EDA is that it is cheap to redo. Wrap it up:
from pathlib import Path
def explore(df: pd.DataFrame, name: str, out_dir: str = "reports") -> None:
Path(out_dir).mkdir(exist_ok=True)
sanity_report(df).to_csv(f"{out_dir}/{name}_sanity.csv")
ProfileReport(df, title=name, minimal=len(df) > 100_000) \
.to_file(f"{out_dir}/{name}_profile.html")
print(f"{name}: {df.shape[0]:,} rows x {df.shape[1]} cols")
Now re-profiling after a cleaning step costs one line, so you actually do it — and you catch the transformation that silently dropped 3,000 rows.
What automation will not do
No tool will tell you that event_id 4471 is a duplicate created by a
re-import, or that attendance dropped in March because of exams. Automation
buys you the time to notice those. It does not notice them for you.