Question:medium

Which of the following function of Pandas will replaces value by the value before the missing value?

Show Hint

In missing value treatment, "pad" is synonymous with "ffill" (forward fill).
It copies the previous row's value down to fill the empty space.
Updated On: Jun 11, 2026
  • df.fillna(method='bfill')
  • df.fillna(method='pad')
  • df.fillna(method='afill')
  • df.fillna(method='fillpad')
Show Solution

The Correct Option is B

Solution and Explanation


Step 1: Understanding the Question:

The question asks about the Pandas function parameter that fills missing values (NaN) with the value that occurs directly before (above) the missing entry in the series or DataFrame column.

Step 2: Key Formula or Approach:

In Pandas, the fillna() method is used to replace null values.
The method parameter specifies how missing values should be propagated:
- ffill or pad: Forward fill (propagates the last valid observation forward to next valid).
- bfill or backfill: Backward fill (propagates the next valid observation backward to previous valid).

Step 3: Detailed Explanation:

When dealing with missing values, a common strategy is to propagate the last known value forward.
This is known as forward filling. In Pandas, this can be achieved using method='pad' (which stands for padding) or method='ffill'.
This replaces any missing value with the non-null value immediately preceding it along the given axis.
Let's look at the options:
- method='bfill' (backward fill) replaces the missing value with the one after (below) it.
- method='pad' is the correct alias for forward filling, which uses the value before the missing value.
- 'afill' and 'fillpad' are not valid parameters in Pandas and will raise a ValueError.
Therefore, df.fillna(method='pad') is the correct syntax.

Step 4: Final Answer:

The correct option is (B), df.fillna(method='pad').
Was this answer helpful?
0


Questions Asked in CUET (UG) exam