apopt.comCBE 493R Data-Driven Athletics

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.

  1. 1Gather (used)
  2. 2Statistics (used)
  3. 3Visualize (used)
  4. 4Cleanse (used)
  5. 5Features
  6. 6Balance
  7. 7Scale
  8. 8Split
  9. 9Deploy
  1. Ask
  2. Collect
  3. Check (this week)
  4. Interpret
  5. Coach
  6. Reassess

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

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.

PythonFind the three kinds of missing

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:

  1. An empty cell is missing, reason empty.
  2. A stance time or vertical bounce of 0 is missing, reason zero code (the watch made no estimate).
  3. 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.
  4. 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.

PythonApply the rules and keep every row

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: 3746

Every 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

PythonStance time with its missing values and pauses marked

Show the expected result without running
missing stance times within 30 s after a pause: 160
Stance time in milliseconds against minutes since the start, about 94 minutes. Dots mostly between about 200 and 300 ms; short vertical marks at the bottom where stance time is missing (empty or zero code), clustered at the start, around the shaded pauses and through minutes 40 to 70; crosses for kept out-of-range values, six single values just under 100 ms and a run of 17 near 470 ms at about minute 69.

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

  1. Why mark a stance time of 0 as missing instead of keeping it as a value?

  2. A stance time of 474 ms is outside the 100 to 400 ms rule. What does the marked copy do with it?

  3. The marked copy has how many rows, compared with the raw file?

0 of 3 answered · 0 right the first time

References

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.