How to backward fill in Python
• 1 minThe Pandas library will give you the tools to backward fill the NaN values.
What is backward fill ?
Backward fill will give the next available value for every NaN.
This useful when you are working with timeseries and need to take the next available values.
Using fillna
The .fillna() method will replace all NaN or null values contained in a pandas.Series ou pandas.DataFrame.
As we could have seen in the fillna article we can specify the method we want to use.
Here for our example we are going to use the forward fill method or "bfill"
Using bfill on a Serie
Using bfill on a DataFrame
Here you are, you know how to replace your NaN by the next available value, or backward fill.
If you want to learn more about forward fill, you can check the links below