Skip to content
Advertisement

Pandas DataFrame – Filling a repeating null value with a preceding none-null value

How do I fill repeating null values with a preceding non-null value?

JavaScript

For instance, the data frame above would be populated as:

[‘a’,’a’,’a’,’b’,’b’,’b’]

Advertisement

Answer

Use df.fillna with the ffill method, as follows:

JavaScript

Example:

JavaScript
Advertisement