Command Palette

Search for a command to run...

Hectal
Back to the lesson: Topic 4.4 — Cleaning Real Data
Data Visualization · Example 1 of 2

Look first: list every problem in the March file

Reading with d3.csv and no autoType keeps every cell as text, so nothing is hidden. The line number is the position in the file (line 1 is the header).

Real exports have blanks, "n/a", numbers with commas, impossible dates and outliers. Look first, then fix only what is certain, flag what is missing, drop what cannot be placed, never invent values, and keep a log of every change.

Change the code and press Run (Ctrl+Enter). Predict what will happen first, then break it on purpose and read what changes. Your edits are saved and match the lesson page.

Ready for more? This phase has 5 hands-on exercises with automatic checks.

Practice questions

Write the code in the editor, run it, then open the model answer to compare.

01

Add a rule to cleanDaily that flags temp_c below −30 or above 45 as null with a reason. Run it on daily.csv and report how many notes it writes.

02

Write missingDays(rows, from, to) returning the YYYY-MM-DD texts of days between two dates that have no row.

Explain it without notes

01

Why is null better than 0 for a missing day?

02

Name three actions a cleaner can take on a bad row, with an example of each.

03

Why does the cleaner refuse to read 2025-03-32 as 25 March?

Look first: list every problem in the March file

Preview

Press Run to see the page.

Console

Nothing logged yet.

Expected console output

32 rows read, 9 problems found:
line  5: rides is blank
line  9: temp_c is 'n/a', not a number
line 12: rides is '2,016', not a number
line 14: date '13/03/2025' is not YYYY-MM-DD
line 17: rain_mm is -1 (a sensor code, not rain)
line 20: weekday 'wed' is not in the same form as the others
line 23: exact duplicate of an earlier row
line 27: date '2025-03-32' is not a real day
line 29: avg_minutes is 1240 (more than 3 hours)