How to fill the missing value with fixed number of consecutive period of a Data frame in python?



I have created a Data Frame in Ipython notebook in which there are some missing value and I have used ffill method to fill the missing the value.

I want that ffill method only fill the first two NAN of each column and reaming NaN should remain as missing value.



Here, limit option of FILLNA will help: Look at the below commands:

#First Created a data frame
import pandas as pd

Above, you can see that data frame has missing values.

#Used ffill method to fill missing values

fillna with ffill method has fill all missing values with previous non missing value

#Used option limit to restrict the value to fill

After using limit=2 option, it has only filled second third observation of third column not the last one.

Hope this helps!