Which of the following function of Pandas will replaces value by the value before the missing value?
Which of the following function of Pandas will replaces value by the value before the missing value?
Solution
✅ Correct Option: 2
method='pad' is the same as 'ffill' (forward fill). It propagates the last valid value forward, so each missing value is replaced by the value just before it.
For example, becomes .
Option 1: 'bfill' is backward fill, which uses the next valid value after the gap, not the one before it.
Options 3 and 4: 'afill' and 'fillpad' are not valid fillna methods in Pandas.
Newer Pandas versions deprecate the method argument in fillna, so df.ffill() and df.bfill() are preferred.
Related questions:
2025: 14 May Shift 1