Skip to content

Missing-value repair and false trends

Apply imputation strategies by sensor type and compare forward-fill choices.

Data Dora, your practice guide

Data Dora
Apply imputation strategies by sensor type and compare forward-fill choices.
Predict the reading, then compare it with the measurement.

Python 3 in your browser (JupyterLite)

Python · no install

Tier 2 · Web · paste-in setup · No account

Last tested October 2026.

Open the notebook in your browser and run each Python cell; no install or account is needed.

Three ways to run: use JupyterLite here with no install; run main.py locally from the downloadable lab folder; or open the same notebook in Google Colab.

Open in your browser (new tab)

Steps

The tool may have moved on since the screenshots were taken — the text steps are the contract.

  1. 1 Step 1

    Do
    Run the Step 1 notebook cell and inspect the timestamped missing markers.
    You will see

    Run the cell. You should see:

    • SYNTHETIC minute-resolution temperature; seed=808; no random draws; minute value_C; 0 20.0; 1 21.0; 2 MISSING
    Why it matters
    An absent record must stay distinguishable from zero.
    Code for step 1
    import platform
    import pyodide
    print(f'Runtime: Python {platform.python_version()} / Pyodide {pyodide.__version__}')
    
    """Short and long missing intervals in synthetic temperature telemetry."""
    import statistics
    
    SEED = 808  # deterministic fixture identifier; no random draws
    TIMES_MIN = list(range(9))
    READINGS_C = [20.0, 21.0, None, 23.0, None, None, None, 30.0, 31.0]
    
    
    def forward_fill(max_gap=None):
        result, flags = READINGS_C.copy(), [False] * len(READINGS_C)
        last, gap = None, 0
        for i, value in enumerate(READINGS_C):
            if value is None:
                gap += 1
                if last is not None and (max_gap is None or gap <= max_gap):
                    result[i], flags[i] = last, True
            else:
                last, gap = value, 0
        if max_gap is not None:
            # A run is accepted or rejected as a whole; do not fill the first
            # minute of a three-minute outage just because its prefix is short.
            start = 0
            while start < len(READINGS_C):
                if READINGS_C[start] is not None:
                    start += 1
                    continue
                end = start
                while end < len(READINGS_C) and READINGS_C[end] is None:
                    end += 1
                if end - start > max_gap:
                    for i in range(start, end):
                        result[i], flags[i] = None, False
                start = end
        return result, flags
    
    
    def display(values, flags=None, start=0):
        return [f"{t:>6} {('MISSING' if x is None else f'{x:.1f}'):>8}"
                + (f" {'FILLED' if flags[t-start] else 'OBSERVED' if READINGS_C[t] is not None else 'MISSING'}" if flags is not None else "")
                for t, x in zip(TIMES_MIN[start:], values)]
    
    
    def mean(values):
        observed = [x for x in values if x is not None]
        return len(observed), statistics.mean(observed)
    
    
    def run_step(n):
        all_values, all_flags = forward_fill()
        short_values, short_flags = forward_fill(1)
        if n == 1:
            lines = ["SYNTHETIC minute-resolution temperature; seed=808; no random draws",
                     "minute value_C", *display(READINGS_C),
                     "MISSING is an absent reading, not a measured zero."]
        elif n == 2:
            count, avg = mean(READINGS_C)
            lines = ["Naive complete-case summary drops missing rows",
                     f"retained={count}; missing={len(READINGS_C)-count}",
                     f"mean of retained values={avg:.3f} C",
                     "retained minute:value_C", *[f"{i}:{x:.1f}" for i, x in enumerate(READINGS_C) if x is not None],
                     "This mean has no values for outage minutes."]
        elif n == 3:
            lines = ["Forward-fill the one-minute gap at minute 2",
                     "minute value_C provenance", *display(all_values[:4], all_flags[:4]),
                     "minute 2 inherits 21.0 C from minute 1."]
        elif n == 4:
            lines = ["Unbounded forward-fill across the three-minute outage",
                     "minute value_C provenance", *display(all_values[3:8], all_flags[3:8], 3),
                     "Minutes 4-6 appear flat at 23.0 C without observations."]
        elif n == 5:
            c1, m1 = mean(all_values)
            c2, m2 = mean(short_values)
            lines = ["Maximum contiguous gap=1 minute; reject longer runs",
                     "minute value_C provenance", *display(short_values[2:8], short_flags[2:8], 2),
                     f"unbounded filled count={c1}, mean={m1:.3f} C",
                     f"gap-limited count={c2}, mean={m2:.3f} C"]
        elif n == 6:
            lines = ["RESULT CARD: synthetic temperature; seed=808",
                     f"original: {mean(READINGS_C)[0]} values, mean={mean(READINGS_C)[1]:.3f} C",
                     f"unbounded fill: {mean(all_values)[0]} values, mean={mean(all_values)[1]:.3f} C",
                     f"max-gap=1: {mean(short_values)[0]} values, mean={mean(short_values)[1]:.3f} C",
                     "short gap filled at minute 2; minutes 4-6 remain MISSING",
                     "A fill flag is needed to distinguish inference from observation.",
                     "This synthetic example does not establish what happened in the outage."]
        else:
            raise ValueError(n)
        lines.append(f"STEP {n} complete")
        output = "\n".join(lines)
        print(output)
        return output
    
    
    
    run_step(1);
    Real JupyterLite notebook output for step 1 of Missing-value repair and false trends.
    Step 1 · Python 3 in your browser (JupyterLite); numbered callout added to a real capture.
  2. 2 Step 2

    Do
    Run the Step 2 notebook cell to read the complete-case count and mean.
    You will see

    Run the cell. You should see:

    • Naive complete-case summary drops missing rows; retained=5; missing=4; 8:31.0; This mean has no values for outage minutes.
    Why it matters
    Dropping missing rows changes the denominator.
    Code for step 2
    run_step(2);
    Real JupyterLite notebook output for step 2 of Missing-value repair and false trends.
    Step 2 · Python 3 in your browser (JupyterLite); numbered callout added to a real capture.
  3. 3 Step 3

    Do
    Run the Step 3 notebook cell to inspect the flagged one-minute forward fill.
    You will see

    Run the cell. You should see:

    • Forward-fill the one-minute gap at minute 2; minute value_C provenance; 3 23.0 OBSERVED; minute 2 inherits 21.0 C from minute 1.
    Why it matters
    Short fills remain inferred values and need provenance flags.
    Code for step 3
    run_step(3);
    Real JupyterLite notebook output for step 3 of Missing-value repair and false trends.
    Step 3 · Python 3 in your browser (JupyterLite); numbered callout added to a real capture.
  4. 4 Step 4

    Do
    Run the Step 4 notebook cell to inspect the false flat segment during the long gap.
    You will see

    Run the cell. You should see:

    • Unbounded forward-fill across the three-minute outage; minute value_C provenance; 7 30.0 OBSERVED; Minutes 4-6 appear flat at 23.0 C without observations.
    Why it matters
    Unbounded fill can make an unobserved interval look stable.
    Code for step 4
    run_step(4);
    Real JupyterLite notebook output for step 4 of Missing-value repair and false trends.
    Step 4 · Python 3 in your browser (JupyterLite); numbered callout added to a real capture.
  5. 5 Step 5

    Do
    Run the Step 5 notebook cell to impose a one-minute maximum contiguous gap and compare means.
    You will see

    Run the cell. You should see:

    • Maximum contiguous gap=1 minute; reject longer runs; minute value_C provenance; unbounded filled count=9, mean=23.889 C; gap-limited count=6, mean=24.333 C
    Why it matters
    A whole-gap limit avoids partly accepting a long outage.
    Code for step 5
    run_step(5);
    Real JupyterLite notebook output for step 5 of Missing-value repair and false trends.
    Step 5 · Python 3 in your browser (JupyterLite); numbered callout added to a real capture.
  6. 6 Step 6

    Do
    Run the Step 6 notebook cell and check which values are observed, filled, or still missing.
    You will see

    Run the cell. You should see:

    • RESULT CARD: synthetic temperature; seed=808; original: 5 values, mean=25.000 C; A fill flag is needed to distinguish inference from observation.; This synthetic example does not establish what happened in the outage.
    Why it matters
    The repaired summary needs its missingness rule beside it.
    Code for step 6
    run_step(6);
    Real JupyterLite notebook output for step 6 of Missing-value repair and false trends.
    Step 6 · Python 3 in your browser (JupyterLite); numbered callout added to a real capture.

Chapter checks

These questions refer to the chapter’s examples. Use the return links to review their answers.

  1. A PIR motion sensor loses 30 seconds of data during a brief network outage. What is the most appropriate imputation choice?

    Return to the chapter’s knowledge check
  2. A motion sensor (PIR) has 30 seconds of missing data due to a network outage. What is the most appropriate imputation strategy?

    Return to the chapter’s knowledge check

Caution

Before you start

Read this before you start.

This synthetic temperature example does not establish what occurred during a real outage.

Technical details
Version tested
Version tested: Python 3.12.7 / Pyodide 0.27.6 in JupyterLite 0.6.4; Chromium real browser capture, 2026-10-09. Date: 2026-10-09.
QR code that opens the Missing-value repair and false trends lab page
Open this lab online: https://iotclass.org/labs/missing-value-false-trends.html

Return to Imputation and Noise Filtering · Browse Labs