Exploratory and applied analysis · lesson 2 of 11
Parts in this lesson
Apd.api.types.is_numeric_dtype(col)is this column numbers?
Bcol.replace(-999, np.nan)a code for missing turned into a real missing value
CProfileReport(df).to_file("profile.html")ydata-profiling, on your computer

Profiling reports, and their limits

Last updated

Some of the EDA checklist can be automated. A profiling tool reads a table and writes a report on every column: its type, missing values, distinct values, range and a histogram. It's quick, and it finds a lot. In this lesson you'll build a small profile yourself, see what the popular tools add, and meet the problem every profile misses: missing values written as a number.

By the end of this lesson you can

  • Profile a table automatically, column by column
  • Say what an automatic profile can and can't know
  • Find missing values hidden as codes like −999, and turn them into real missing values

A profile in ten lines

The Lipa store's new till exports one row per receipt. The owners send the first two weeks of December 2024: data/raw/till_2024-12.csv. The first cell defines profile(df), which makes one row per column with the facts a profiling tool reports first. Run the cells.

till.ipynb

In one table: 1,828 receipts, every receipt id unique, 14 dates, hours from 6 to 21, two payment methods, and no missing values anywhere. The value_counts cell checks the category: 1,212 cash and 616 GCash, spelled consistently.

Writing your own profile once is worth it: you know exactly what each number means. Look again at the items row, though. We'll come back to it in step 3.

Profiling tools

On your computer, a library does all this and more. The best known is ydata-profiling (it used to be called pandas-profiling):

from ydata_profiling import ProfileReport

ProfileReport(till, title="Lipa till, December 2024").to_file("reports/till_profile.html")

It writes a web page with a section for every column (type, missing, distinct values, a histogram, the most common values), correlations between columns, sample rows, and a list of alerts: columns with many zeros, high correlations, skewed distributions, duplicate rows. A smaller tool, skimpy, prints a summary like describe() with small histograms in the notebook itself.

They're good at the mechanical half of the checklist: they never forget a column, and on a 60-column table they save an hour. Use one on any new dataset. Then read its report the way you'd read anyone else's work: as claims to check.

Wrong way: “no missing values”

The profile said items has no missing values. A report built on it says: "The average Lipa receipt in December had −135 items." Run the cells.

till.ipynb

Here is what the profile's own histogram of items would have shown, if anyone had looked:

Items per receipt, with and without the −999 code. The profile's histogram of items: 1577 receipts with 1 to 19 items, and a separate bar far to the left. The profile still says “0 missing”.−999: 251 receipts1 to 19 items: 1577-1,000-500005001,0001,500items on the receiptreceipts
1 of 3 The profile's histogram of items: 1577 receipts with 1 to 19 items, and a separate bar far to the left. The profile still says “0 missing”.
  • The mean is −134.95 items. Impossible, so it's easy to spot here; with a smaller code, or a column like "age", the mean would just look a little wrong.
  • The second cell finds where the negative values are: only on 9, 10 and 11 December, 251 receipts in all. The till's software was updated on the 9th, and for three days it wrote −999 whenever it didn't record the item count.
  • After replace(-999, np.nan), items has 251 missing values and the mean is 2.57 items.

To pandas, −999 is a number like any other, so a profile counts it as present. Codes like −999, 9999, 0, "N/A", "none" or "-" for missing values are common in exported data, government data and surveys.

The check: in the profile, read the min and max of every number column and ask whether they're possible. A minimum of −999 items, or an age of 999, is a code. Then turn codes into missing values as the file is read, with pd.read_csv(..., na_values=[-999]), and write in your notes what the code meant and where it came from.

What a profile can't know

A profile describes the table. It can't know what the table is supposed to describe. Things only a person (or a written check, 5.9) can catch:

  • Impossible but plausible values: a receipt for ₱1,252 is possible; whether it's a mistake depends on what the store sells.
  • Missing rows: a day with no receipts at all doesn't appear in the profile; it's simply not there. Count the rows per day (4.7) to see gaps.
  • Meaning: whether pesos includes the GCash fee, whether hour is the opening or closing of a sale, whether a "receipt" can be a refund.
  • Changes over time: the till update on 9 December. A profile of the whole table mixes the days before and after.

So use the profile to make the first list of questions fast, then do the rest of the checklist by hand, and ask the people who made the data.

Check what you learned

A profile says an “age” column has no missing values, minimum 0 and maximum 999. What should you suspect?
Which of these can an automatic profile find on its own?

Sources

Every example on this page was run with Python 3.14, and its output and error messages are copied from it. These pages cover the same ground in more depth.

All sources for Simple Data Analysis