df
Fruits Veg Non_veg
1 Apple Broccoli Chicken
2 Banana Nan Nan
3 Nan Tomato Nan
In the above sample data frame, I have Nan values and I need to fill it with forward filling all at once and the code I used is :
df[['Fruits','Veg','Non_veg']].fillna(method='ffill',inplace=True)
Is this way of coding is correct ? also if the forward filling cell has another Nan value like in the above data frame how to overcome?
The Expected output for ffill is:
df
Fruits Veg Non_veg
1 Apple Broccoli Chicken
2 Banana Broccoli Chicken
3 Banana Tomato Chicken