Course / Tutorials / Week 4 / Q-12
Quick tutorial Q-12 · Week 4 · about 20 min · Foundation
Find and mark the missing values without deleting anything
Find empty cells, zero codes and gaps in time in one of the instructor's watch files, mark each with a reason in a copy that keeps every row, and see where the missing values cluster.
- 1Gather (used)
- 2Statistics (used)
- 3Visualize (used)
- 4Cleanse (used)
- 5Features
- 6Balance
- 7Scale
- 8Split
- 9Deploy
- Ask
- Collect
- Check (this week)
- Interpret
- Coach
- Reassess
Download notebook ·Python file ·Read as Markdown ·Data folder ·Chapter 4 (sections 4.3)
Every cell runs in this page; the first run downloads Python (about 30 s). Nothing you load leaves your browser. Helpful first: Q-11 Write a data dictionary for one file.
The decision
A runner wants an average contact time for a run. Before averaging, decide which values are not measurements at all, mark them with a reason, and keep every row so nothing else is lost.
The raw data
raw/2026-05-11_1507_running.csv: one second-by-second record of a 10.5 km run (3,746 rows, 12 columns) with empty cells, zero codes and pauses. The instructor's own run on 11 May 2026, from the course case fileathletes/jh/watch/records/, published under his name.
Try it
Mark, don't delete
A missing value can hide in three places: an empty cell, a code that stands for "no value" (a 0 where 0 is impossible), and a row that was never written (a gap in the time stamps). Deleting rows that hold one bad cell throws away the good cells beside it, and deleting a value you do not understand may throw away the event you were looking for (Section 4.3). So mark every missing value, say why, and keep every row.
The file is the instructor's 11 May 2026 run from Q-11, one row a second, and the rules come from the dictionary written there.
Type a prediction to enable Run.
Show the expected result without running
3746 rows; empty cells: 4074 stance time written as 0: 574; vertical bounce written as 0: 525 21 gaps over 2 s, 31.9 min in all; longest 13.3 min
Rules first, then a marked copy
The rules, written before they are applied:
- An empty cell is missing, reason
empty. - A stance time or vertical bounce of 0 is missing, reason
zero code(the watch made no estimate). - A stance time outside 100 to 400 ms is kept and flagged, reason
outside range: it may be an error, or it may be the stride you care about. - A gap in time is recorded on the row after it (
gap_before_s); no rows are invented.
The marked copy has the same rows as the raw file, the codes replaced by empty values, and one reason column per field.
Show the expected result without running
field reason rows
speed_mps empty 37
heart_rate_bpm empty 1
cadence_spm empty 39
altitude_m empty 101
power_w empty 39
stance_time_ms zero code 574
stance_time_ms empty 37
stance_time_ms outside range 24
vertical_oscillation_mm zero code 525
vertical_oscillation_mm empty 37
step_length_mm empty 37
temperature_c empty 3746
rows in: 3746, rows out: 3746Every row is still there. Rule 2 turned 574 stance times and 525 bounces of 0 into honest empty values, so an average of stance time is now an average of real contacts. Temperature is flagged empty in all 3,746 rows: the watch never recorded it.
One chart
Show the expected result without running
missing stance times within 30 s after a pause: 160

The marks are not scattered at random. They cluster at the start, around the pauses, and through minutes 40 to 70, where short fast efforts alternate with walking: the watch stops estimating contact time while the runner walks or stands and needs a few seconds to start again. That pattern is information. Now look at the kept out-of-range values. The six just under 100 ms are single seconds, four of them at walking speed: likely errors. The 17 seconds near 470 ms in a row, at about 1.5 m/s, are a walk, and long contacts are normal when walking; the 100 to 400 ms rule was written for running. A rule that deleted every row with a missing or odd stance time would have removed the start of every effort and the walk between them.
For the athlete: "Contact time was measured for most of your running; the gaps are at the start and around your stops, so your average contact time describes your running, not your stops."
With your own data
Run the same cells on one of your own exported activities, with the rules from your own data dictionary (Q-11). Look at where the missing values fall before you decide anything about them.
Check yourself
Why mark a stance time of 0 as missing instead of keeping it as a value?
A stance time of 474 ms is outside the 100 to 400 ms rule. What does the marked copy do with it?
The marked copy has how many rows, compared with the raw file?
References
- Data-Driven Athletics, Chapter 4, Cleaning (Section 4.3) and Keep the raw file: provenance and a change log (Section 4.3.1).
Built 2026-11-30 with Python packages numpy 2.5.5, pandas 3.1.1, matplotlib 3.11.2. In the browser the same code runs on Pyodide, so the last digit can differ.