Guide
Loggers drop samples, sensors freeze, and timestamps arrive unevenly. Before you resample or model, you have to decide how to fill gaps in your time series — and every method lies in a different way. Here are five, with the case where each one breaks.
A few missing samples in a fast, smooth channel are very different from a multi-minute sensor freeze during a transient. Fixing them the same way is how bad interpolation ends up in a report. And irregular timestamps are their own problem — a method that counts rows treats a 1-second gap the same as a 10-minute one.
import pandas as pd
df["t"] = pd.to_datetime(df["t"])
df = df.set_index("t")
reg = df.resample("1s").mean() # put it on a regular grid
reg["v"] = reg["v"].ffill()
Breaks when the signal is moving. Forward-fill draws a staircase and invents a plateau that was never measured — fine for a slow set-point, wrong for a ramp.
reg["v"] = reg["v"].interpolate(method="time") # respects real time spacing
Breaks when the gap spans a peak or fast transient — it cuts the corner and reports a straight line through what may have been the most important part.
reg["v"] = reg["v"].interpolate(method="spline", order=3)
Breaks when the gap is wide: splines overshoot near edges and invent wiggles that look like real dynamics. Smoothness is not accuracy.
If another channel is physically related — a second thermocouple, a paired cell, a coupled axis — reconstruct the missing one from the channels that kept recording, instead of guessing from the gap’s own edges. This is the only method that uses information from outside the gap, and it is the most accurate when such a relationship exists.
Breaks when no correlated channel exists, or the relationship itself changed during the gap.
Sometimes the honest answer is to mark the gap and not fill it, so downstream analysis knows the data is absent rather than invented. For anything feeding a certification or a paper, a flagged gap beats a plausible fabrication.
| Situation | Use |
|---|---|
| Short gap, smooth channel | linear (by time) |
| Gap over a transient | correlated-channel, or flag |
| Slow set-point held constant | forward-fill |
| Wide gap | flag or model-based, not spline |
Put the series on a regular grid with pandas resample, then interpolate by time for short gaps. Use forward-fill only for held set-points, and avoid splines on wide gaps.
Convert to datetime, set it as the index, and resample to a fixed interval before interpolating, so a long gap is not treated like a short one.
No. Over a transient or a wide gap, reconstructing from a correlated channel or simply flagging the gap is more honest than inventing values that interpolation makes look real.
Skip the code. Drop your CSV into the free browser demo — no sign-up — and get a denoised, gap-filled, de-spiked file back in a minute. Every column, priced by volume when you need more. See the tool →