Profile DataFrames with Pandas Profiling

Profile DataFrames with Pandas Profiling — Data Analysis with Python tutorial, lesson 52.

Focus: profile dataframes with pandas profiling

Sponsored

Ever opened a new dataset and felt that small panic — thousands of columns, mixed types, missing values lurking everywhere? You know you should check for duplicates, outliers, and cardinality before any serious analysis, but writing all those df.isnull().sum() checks by hand feels like a chore. That's the exact pain this lesson kills. Pandas Profiling turns a raw DataFrame into a complete, interactive HTML report in one line of code, giving you the full statistical story of your data before you write a single analysis script.

The problem this lesson solves

Data exploration is where most analysis time disappears. You might start with df.head(), then df.info(), then a few describe() calls, then cross-tabulations, then correlations… before you know it, you've written 50 lines of exploratory code and you still haven't checked every column for skewed distributions or high-cardinality categories.

Traditional manual profiling is slow, error-prone, and easy to skip when you're in a hurry. You might miss a column with 90% missing values, fail to notice a variable with 500 unique string values, or overlook a strong correlation that would have changed your entire approach.

Pandas Profiling (now ydata-profiling) solves this by generating a deep, visual, and exhaustive report of your DataFrame automatically. It calculates:

  • Basic statistics (mean, median, standard deviation, quantiles)
  • Missing value counts and percentages per column
  • Unique values and cardinality
  • Histograms and distribution plots
  • Correlation matrices (Pearson, Spearman, Kendall, phi_k)
  • Type inference (category, numeric, boolean, etc.)

You get a comprehensive picture of your data quality in seconds — not in an hour of manual coding.

Core concept / mental model

Think of Pandas Profiling as the MRI scan for your DataFrame. You don't just get a head() — that's like a doctor peeking at your chart. The profile report gives you a full-body scan: every column's distribution, every missing value, every correlation, every type quirk.

The mental model has three layers:

  1. Input: a pandas DataFrame (any size, from hundreds to millions of rows)
  2. Process: the library walks through each column, detects its data type, computes descriptive statistics, and builds interactive visualizations
  3. Output: a self-contained HTML report you can open in any browser, export, or share with your team

This is exploratory data analysis (EDA) on autopilot. Instead of asking "what should I explore?" you ask "what does the data look like?" — and the report answers with charts and tables.

Pro tip: Pandas Profiling was formerly called pandas-profiling. The package was renamed to ydata-profiling — install the new name to get the latest features and security fixes.

How it works step by step

Here's the logical flow of how Pandas Profiling does its magic:

  1. Installationpip install ydata-profiling (the library pulls in pandas, numpy, matplotlib, and jinja2 for rendering)
  2. Import and createfrom ydata_profiling import ProfileReport
  3. Generate the reportprofile = ProfileReport(df, title="My Report")
  4. Render or export — call profile.to_file("report.html") or use profile.to_notebook_iframe() inside a Jupyter notebook
  5. Inspect — open the HTML in your browser, navigate through tabs: Overview, Variables, Interactions, Correlations, Missing values, Sample

The library decides, for each column, whether it's numeric, categorical, boolean, date, or otherwise. For numeric columns, it computes percentiles, mean, std, skewness, kurtosis, histogram; for categoricals, it gives the number of unique values, most frequent — both absolute and relative — and a pie chart. It also flags columns that are highly correlated or have high missingness — the report even suggests alerts like "high correlation" or "missing values".

Hands-on walkthrough

Let's put this into practice. We'll use the classic Iris dataset (built into seaborn) to generate a full profile report in under a minute.

Step 1: Install the package

pip install ydata-profiling

If you're in a Jupyter notebook, you may also need to enable the widget extension (not strictly required for the HTML output):

jupyter nbextension enable --py widgetsnbextension

Step 2: Create a DataFrame and generate the report

import seaborn as sns
from ydata_profiling import ProfileReport

# Load the iris dataset
iris = sns.load_dataset("iris")

# Generate the profile report
profile = ProfileReport(iris, title="Iris Dataset Profiling Report")

# Save the report to an HTML file
profile.to_file("iris_report.html")

print("Report generated: iris_report.html")

Expected output: a file iris_report.html in your working directory. Open it in a browser — you'll see:

  • Overview: total rows (150), total variables (5), missing cells (0), duplicate rows (0)
  • Each variable's statistics: sepal_length mean ≈ 5.84, etc.
  • A correlation matrix showing strong positive correlation between sepal_length and petal_width (~0.82)

Step 3: Explore the report in a notebook

# Inside a Jupyter notebook, embed the report directly
profile.to_notebook_iframe()

This creates an interactive widget showing the same report without leaving your notebook. You can click through tabs — Variables (each column's stats), Interactions (scatter plots of numeric pairs), and Sample (first/last rows).

Step 4: Filter the report to focus on columns you care about

# Only profile a subset of columns
profile_subset = ProfileReport(iris[['sepal_length', 'species']], title="Iris subset profile")
profile_subset.to_file("iris_subset_report.html")

That's it. Two lines of code gave you a report that would have taken 30 minutes to build manually with matplotlib and pandas. Now you can spend your time actually analyzing, not counting.

Compare options / when to choose what

Pandas Profiling is not the only way to profile a DataFrame. Here's a quick comparison with other popular tools:

Tool Output Interactivity Speed Best for
Pandas Profiling (ydata-profiling) HTML report / notebook High (tabs, charts) Medium (on large data might be slow) Quick deep EDA, sharing with non-technical teammates
df.describe() Plain table of summary stats Low Instant Quick numeric summary for numeric columns
df.info() Column types + memory usage Low Instant Quick check of columns and missing non-null counts
D-Tale Interactive web app Very high (click-through heatmaps, charts) Medium In-depth interactive exploration, data cleaning UI
Sweetviz HTML report (comparative) Medium Fast Comparing two datasets (e.g., train vs test)
sklearn + missingno Custom pipeline + missingness visualization Low Custom When you need full control over the profiling pipeline

When should you reach for Pandas Profiling?

  • When you get a new dataset and want a quick, thorough overview
  • When you need to present data quality findings to stakeholders
  • When you're doing a first-pass EDA before feature engineering

When might you avoid it?

  • On huge datasets (millions of rows and hundreds of columns) where the report generation becomes slow or memory-heavy — you may want to sample first
  • If you only need a quick df.describe() — don't pull in a heavy library for that

Pro tip: For datasets larger than ~100k rows, consider passing minimal=True to ProfileReport(df, minimal=True) — it skips the heavy interactions and correlations, generating a lightweight report in a fraction of the time.

Troubleshooting & edge cases

Let's look at common issues you might hit and how to fix them.

1. ModuleNotFoundError: No module named 'ydata_profiling'

You haven't installed the package, or you installed the old pandas-profiling. Fix:

pip install ydata-profiling

If you already have the old one, uninstall it first:

pip uninstall pandas-profiling

2. The report is generated but the HTML file is huge (20+ MB)

With many rows, the interactions and sample tabs can bloat the file. Use minimal=True to cut the size:

profile = ProfileReport(df, minimal=True)
profile.to_file("tiny_report.html")

3. The report takes forever on a 2M-row dataset

Pandas Profiling has to compute statistics and correlations for every column — that's O(n) at best and O(n^2) for correlations. For wide datasets, consider:

  • Sampling: df.sample(1000) then profile
  • Passing progress_bar=False if you're not in a notebook
  • Reducing the number of columns to the most important ones

4. ValueError: can only convert an array of size 1 to a Python scalar

This usually happens when a column contains mixed types (e.g., some numbers, some strings). Pandas Profiling tries to infer types and may choke. Fix: clean your DataFrame first — coerce the column to a single type using pd.to_numeric() or convert to string, then profile again.

5. The report shows "constant value" alert for a column

This is not an error — it's a feature! Pandas Profiling flags columns that have only one unique value, which are often useless for modeling. It's a great hint to drop that column.

What you learned & what's next

You've learned how to profile dataframes with pandas profiling — the core idea, the step-by-step process, and real-world troubleshooting. You can now:

  • Explain why automated profiling beats manual describe() calls for a quick, deep EDA
  • Generate and export an HTML report with ydata-profiling in two lines of code
  • Interpret the main sections: overview, variables, correlations, and missing values
  • Choose when to use Pandas Profiling vs. df.describe() vs. other tools
  • Handle common errors like missing imports, slow reports on big data, and type mixing

Next lesson in the track — you'll take the insights from your profile report and use them to clean and preprocess your data. You'll learn how to handle missing values (imputation, deletion), remove constant columns, and deal with high-cardinality categories — techniques that directly rely on the alerts you now know how to generate. So keep your iris_report.html handy; you'll use it as a checklist for data preparation.

Remember: profiling is not the end — it's the beginning. The report tells you where to look, but the cleaning is where the real magic happens.

Practice recap

Take a dataset you work with frequently (or use seaborn.load_dataset('titanic')) and generate a profile report with ydata-profiling. Open the HTML report and write down the top 3 alerts it flags — e.g., missing values in 'age', a constant column, or a strong correlation. Then in the next lesson, we'll turn those alerts into a concrete cleaning plan.

Common mistakes

  • Forgetting to install ydata-profiling and importing pandas_profiling (old name) — you'll get a ModuleNotFoundError.
  • Running the profile on the entire dataset without sampling or minimal=True — the report becomes painfully slow on million-row datasets.
  • Ignoring the alerts section — Pandas Profiling flags high correlation, missing values, constant columns, and you're missing out on crucial data quality insights if you skip that tab.
  • Trying to profile a column with mixed types (strings + numbers) without cleaning — the report fails with a ValueError and you waste time debugging.

Variations

  1. Switch to dataprep.eda — a modern alternative that creates interactive EDA plots (e.g., create_report(df)) with a similar one-line API but a slightly different visual style.
  2. Use sweetviz for comparative profiling — it lets you compare two DataFrames (like train/test splits) side-by-side in one HTML report.
  3. Combine Pandas Profiling with missingno for a specialized view of missingness — the profile gives you counts, while missingno gives you matrix and bar visualizations to spot patterns.

Real-world use cases

  • Onboarding a new client dataset in a consulting project — generate a profile report to present data quality and potential issues in the first stakeholder meeting.
  • In an ML pipeline, run a profile report on the training set before feature engineering to detect constant columns, high-cardinality categories, and target leakage indicators.
  • Sharing a data quality assessment with a non-technical product team by exporting the HTML report — they can explore distributions and missing values without writing any code.

Key takeaways

  • Pandas Profiling (now ydata-profiling) automates exploratory data analysis by generating a rich HTML report in one line of code.
  • The report includes overview stats, per-variable distributions, missing value heatmaps, correlation matrices, and data quality alerts.
  • Use minimal=True and consider sampling for large datasets to keep report generation fast and the HTML file size manageable.
  • Profile reports are excellent for sharing data insights with non-technical stakeholders and for guiding your data cleaning steps.
  • Always check the alert section — it flags high-correlation pairs, high missingness, and constant columns — which informs your feature selection.
  • Next step after profiling is data cleaning: use the profile findings to impute or drop missing values, remove constant columns, and handle high-cardinality categories.

Sponsored

Sponsored