Skip to main contentSkip to solution

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, [5,NaN,NaN,8][5, \text{NaN}, \text{NaN}, 8] becomes [5,5,5,8][5, 5, 5, 8].


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.

Keyboard Shortcuts

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