apopt.comCBE 493R Data-Driven Athletics

Course / Tutorials / Week 4 / Q-11

Quick tutorial Q-11 · Week 4 · about 20 min · Foundation

Write a data dictionary for one file

Write a data dictionary for one of the instructor's per-second watch files, with units, allowed ranges and missing-value codes, before looking at the values, then count which rows break which rule.

  1. 1Gather (used)
  2. 2Statistics (used)
  3. 3Visualize
  4. 4Cleanse (used)
  5. 5Features
  6. 6Balance
  7. 7Scale
  8. 8Split
  9. 9Deploy
  1. Ask
  2. Collect (this week)
  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-10 Open a phone sensor log and plot it.

The decision

A runner wants contact time and cadence from a season of watch files. Before any average, write down what each column means, in which unit, what values are possible, and how the file says "no value".

The raw data

Try it

A file does not say what it means

A data dictionary is a table with one row per field of a file: its name, its meaning, its unit, its type, its allowed range and its missing-value code, the way the file writes "no value" (Section 4.2.5). The file here is one of the instructor's real runs, the 11 May 2026 afternoon run from the course case file: one row per second the watch recorded, 12 columns, GPS positions removed. Open it and list what is there.

PythonWhat is in the file?

Type a prediction to enable Run.

Show the expected result without running
(3746, 12)
                time elapsed_s distance_m speed_mps heart_rate_bpm cadence_spm altitude_m power_w stance_time_ms vertical_oscillation_mm step_length_mm temperature_c
2026-05-11T21:07:12Z       0.0        0.0       NaN            NaN         NaN        NaN     NaN            NaN                     NaN            NaN           NaN
2026-05-11T21:07:13Z       1.0        0.0       NaN             87         NaN        NaN     NaN            NaN                     NaN            NaN           NaN
2026-05-11T21:38:17Z    1865.0     3014.5     3.358            127         174     1408.0     249          205.0                   101.0         1160.0           NaN
empty cells per column: {'time': 0, 'elapsed_s': 0, 'distance_m': 0, 'speed_mps': 37, 'heart_rate_bpm': 1, 'cadence_spm': 39, 'altitude_m': 101, 'power_w': 39, 'stance_time_ms': 37, 'vertical_oscillation_mm': 37, 'step_length_mm': 37, 'temperature_c': 3746}

3,746 rows for a run whose last elapsed_s is 5,640: the watch writes no rows while it is paused. The temperature_c column is empty in every row. Now write the dictionary before checking the values against it. The meanings and units come from the case file's own description; the allowed ranges are your rules, set from what a runner can do, not from this file.

PythonThe dictionary, written first

Show the expected result without running
                  field          unit    low     high    missing
                   time ISO 8601, UTC    NaN      NaN      never
              elapsed_s             s    0.0  36000.0      never
             distance_m             m    0.0 100000.0      never
              speed_mps           m/s    0.0     12.0      empty
         heart_rate_bpm     beats/min   30.0    220.0      empty
            cadence_spm     steps/min    0.0    240.0      empty
             altitude_m             m -500.0   5000.0      empty
                power_w             W    0.0   1500.0      empty
         stance_time_ms            ms  100.0    400.0 empty or 0
vertical_oscillation_mm            mm   30.0    150.0 empty or 0
         step_length_mm            mm    0.0   2500.0      empty
          temperature_c         deg C  -30.0     60.0      empty

Two rows carry most of the value. Cadence here counts both feet (a watch's own file often counts one, Section 4.2.5), so the range is up to 240. And a stance time of 0 ms is not a contact; the case file notes that the watch writes 0 when it did not estimate one, so 0 is a second missing-value code for stance time and vertical bounce.

Check the file against it

PythonCount what breaks each rule

Type a prediction to enable Run.

Show the expected result without running
                         empty  not a number  0 = no estimate  outside range
field                                                                       
elapsed_s                    0             0                0              0
distance_m                   0             0                0              0
speed_mps                   37             0                0              0
heart_rate_bpm               1             0                0              0
cadence_spm                 39             0                0              0
altitude_m                 101             0                0              0
power_w                     39             0                0              0
stance_time_ms              37             0              574             24
vertical_oscillation_mm     37             0              525              1
step_length_mm              37             0                0              0
temperature_c             3746             0                0              0
stance time 0 while slower than 2 m/s (walking or stopped): 492 of 574
stance times outside 100-400 ms: shortest 82, longest 474

One chart

PythonWhere the file breaks its dictionary

Show the expected result without runningHorizontal bars, one row per field, of the number of rows that are empty, use the zero code, or fall outside the allowed range. Temperature is empty in all 3,746 rows; stance time and vertical bounce have several hundred zero-code rows; altitude has about 100 empty rows; the other fields have few.

The file passes most of its rules, and the failures are informative. Temperature was never recorded. Stance time and vertical bounce use 0 for "no estimate" in several hundred rows, mostly while walking or stopped, which an average would otherwise count as real contacts of zero length. The few values outside range, 24 stance times and one vertical bounce, are for Q-12 to mark, not to delete. Update the dictionary with what you found: the zero code is now written down for the next person.

For the athlete: "Your watch file is in good shape for pace, heart rate and cadence; contact time is missing for about one second in six, so we'll report it only from the seconds where the watch measured it."

With your own data

Export one activity from your own watch or phone app as CSV (or convert a FIT file with the fitdecode library, Q-16), write its dictionary before you look at the values, and run the check. Remove any position columns before you share the file.

Check yourself

  1. Why read the file as text first (dtype=str)?

  2. A stance time of 0 ms appears in several hundred rows. What is the right entry in the dictionary?

  3. The file has 3,746 rows, but the run lasted 5,640 s from start to finish. What explains the difference?

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.