Which method is used to replace the missing values by the value before the missing value?
Which method is used to replace the missing values by the value before the missing value?
Solution
✅ Correct Option: 1
df.fillna(method='pad') is correct because 'pad' is forward fill. It copies the last valid value forward into the missing cell, so each NaN is replaced by the value just before it.
'pad' is the same as 'ffill', and df.ffill() does the same job.
Option 3: 'bfill' is backward fill, so it uses the value after the missing one.
Options 2 and 4: pandas has no fill_na method. The correct name is fillna, without the underscore.
Related questions:
2025: 27 May Shift 2
2026: 24 May Shift 1
2026: 26 May Shift 1