O'Reilly logo

Learning pandas - Second Edition by Michael Heydt

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Forward and backward filling of missing values

Gaps in data can be filled by propagating the non-NaN values forward or backward along a Series. To demonstrate, the following example will fill forward the c4 column of DataFrame:

When working with time series data, this technique of filling is often referred to as the "last known value". We will revisit this in the chapter on time-series data.

The direction of the fill can be reversed using method='bfill':

To save a little typing, pandas also has global level functions pd.ffill() and pd.bfill() ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required