Exploratory and applied analysis · lesson 1 of 11
Parts in this lesson
Adf.shape, df.dtypes, df.isna().sum()3.2: the first three questions for any table
Bdf.groupby(...)[col].describe()4.1: a summary for each group
Cdf[[...]].corr()8.9: every pair of number columns

An EDA workflow

Last updated

Stage 9 starts with a new file: three years of the Tindahan books, one row per store per month. Before answering anything with it, explore it, in the same order every time, so nothing gets skipped: questions first, then the shape of the table, one column at a time, two at a time, and a list of surprises. In this lesson you'll follow that order, and see how a conclusion drawn from the first chart goes wrong.

By the end of this lesson you can

  • Explore a new dataset in a fixed order
  • Check shape, types and missing values before any chart
  • Look at one variable, then pairs, then many
  • Write down surprises, and check one before believing it

Questions first

The owners have kept monthly books since January 2022: for each store and month, the days it was open, the number of receipts and the pesos taken. The file is data/clean/books.csv. Stage 9 uses it to answer the questions owners ask every month: how are we doing, compared with what, and why?

Exploratory data analysis (EDA) is looking at a dataset from several sides before trying to answer anything with it. John Tukey, who named it in the 1970s, compared it to detective work: gather the clues before deciding what happened. Explore in the same order every time, so you don't skip the boring checks that catch the big mistakes. Tick each item as you do it in this lesson:

EDA checklist0 of 6

Step 1 is yours: before running anything, write two questions in a Markdown cell, such as “Which store is growing fastest?” and “Is December the best month everywhere?”.

Shape, types and missing values

Run the cells.

09-explore.ipynb
  • 144 rows and 5 columns: 36 months × 4 stores, so one row is one store in one month. Say that sentence out loud for every new table; most mistakes in a join or a sum start with getting it wrong.
  • Types: month is a date (because of parse_dates), store is text, and the three measures are whole numbers. No pesos stored as text (3.7).
  • No missing values, and all four stores for all 36 months.

One variable at a time

Now each column on its own. Run the cells.

09-explore.ipynb
  • Batangas takes the most in a typical month (median ₱89,383), then Lipa, Tanauan and Rosario. Tanauan's months are the most spread out for its size, from ₱41,079 to ₱87,374: a hint that it's changing, which a chart over time will show.
  • days_open should match the days in the month. Most rows have 30 or 31, and 28 or 29 are Februaries. But there's one 27, and nine 28s, when the 28-day Februaries of 2022 and 2023 explain only eight (4 stores × 2). There are also six 29s for the four of February 2024. Note it as a surprise.

Two at a time, and many

Run the cells.

09-explore.ipynb
  • Over time: every store peaks in December and dips early in the year; Tanauan climbs steadily, and Rosario is nearly flat. These are the questions for 9.4 to 9.6.
  • Correlations: receipts and pesos move together almost perfectly (0.99), so the average receipt hardly changes. Days open barely correlates with anything, because it only varies by a day or two.
  • The surprise, checked: rows where the store was open fewer days than the month has. All four are October 2024: Batangas 28 days, Lipa 29, Tanauan 29, Rosario 27. A typhoon hit at the end of October, and the stores closed. That's worth a line in the notes.

Write your surprises in a Markdown cell, each with what explains it, or "not explained yet":

  1. All four stores were closed for 2 to 4 days in October 2024 (typhoon). Compare that month per day open.
  2. Tanauan grew much faster than the others. Why? (Ask the owners.)

Wrong way: the first chart

An owner looks at Rosario's last six months and writes: "Rosario fell 9% in October. Something's wrong there; we should look at the staff." Run the first cell to see what they saw.

09-explore.ipynb

October's takings were 9.1% below September's. Now the second cell: the same months, per day open. Rosario was open 27 days in October, against 30 in September, and per open day it took 1.1% more. The fall was the typhoon closing the store for four days, not anything about how it was run.

The first chart answered "what happened to the total?" before anyone had checked what the total was made of. It was correct and still misleading.

The check: before drawing a conclusion from a chart, go back to the rows behind the odd point and look at every column, not just the one on the chart. The EDA order exists for this: the days_open surprise in step 3 was found before any chart, and it explains this one.

Check what you learned

A new file has 1,460 rows: one per store per day for one year. How many stores is that likely to be?
Why check types and missing values before drawing any charts?
Predict: a store took ₱31,000 in a 31-day month and ₱28,000 in a 28-day month. Per day, did it do better or worse in the second month?

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