Course contentsShow
← Machine Learning and Deep Learning
Lesson 433 of 3,53810. Feature EngineeringFree lesson

Forward Fill and Backward Fill for Time Series

Using propagation methods to impute missing values in sequential data while preserving temporal structure.

Forward Fill and Backward Fill for Time Series

You'll learn how to handle missing values in time-ordered data by borrowing information from adjacent time points without breaking temporal logic.

The Core Idea

When working with time series data (like daily stock prices, sensor readings, or weather measurements), missing values create gaps. Forward fill (also called "last observation carried forward") fills gaps by copying the last known value forward in time. Backward fill does the opposite: it pulls the next known value backward to fill the gap.

Think of it like a daily temperature log with a missing entry on Wednesday. Forward fill assumes Wednesday's temperature was the same as Tuesday's. Backward fill assumes it was the same as Thursday's.

Why This Matters for Time Series

Unlike random imputation methods, forward and backward fill respect the temporal ordering of your data. They acknowledge that values closer in time are more similar—a reasonable assumption for many real-world sequences.

Forward fill is more common because it mimics how information flows in time: you only know the past, not the future. It's appropriate when values change slowly (e.g., a person's weight logged weekly).

Backward fill is useful when you know the sequence will continue and want to use future information (e.g., filling hourly data when you have the next hour's reading).

When to Use Each

  • Forward fill: Default choice for most time series; preserves causality
  • Backward fill: When future values are known and relevant
  • Combination: Apply forward fill first, then backward fill to catch any remaining gaps at the start

Key Takeaway: Forward and backward fill preserve temporal structure by propagating adjacent values through time, making them ideal for sequential data where nearby observations are naturally similar.