Skip to main contentSkip to solution

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.

Keyboard Shortcuts

  • Left arrow: Previous question
  • Right arrow: Next question
  • S key: Jump to solution
  • Q key: Jump to question