Skip to main contentSkip to solution

Which pandas function replaces the missing value by the value placed before the missing value?

Solution

✅ Correct Option: 2

fillna(method='pad') is a forward fill. It carries the last valid value forward, so each missing value is replaced by the value placed just before it.

'pad' is an alias of 'ffill' (forward fill).


Option 1: 'bfill' is backward fill, which uses the next valid value after the missing one.

Options 3 and 4: 'nfill' and 'padded' are not valid fill methods in pandas.

Keyboard Shortcuts

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