Skip to main contentSkip to solution

Which function do we use to fill the missing values with previous entry?

Solution

✅ Correct Option: 2

.fillna(method='pad') is the pandas forward-fill. It replaces each missing value (NaN) with the previous non-null entry in the same column. 'pad' is an alias of 'ffill'.


Option 3: 'bfill' is backward fill. It uses the next valid entry, not the previous one.

Options 1 and 4: .dropna() removes rows with missing values instead of filling them. how='all' drops only rows where every value is NaN.

In newer pandas versions, method= in fillna is deprecated, and .ffill() is preferred.

Keyboard Shortcuts

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