Question:medium

We can add a new row to a DataFrame DF using the ______ method.

Show Hint

Assign values to a new row label with square brackets. That is the loc indexer.
Updated On: Oct 20, 2026
  • DF.add()
  • DF.loc[]
  • DF.loc()
  • DF.addloc[]
Show Solution

The Correct Option is B

Solution and Explanation

Step 1: Start from the options:
Two of them are not real names, or are used for other jobs, so check them first.
DF.addloc[] is not a Pandas attribute. Python raised an AttributeError for it.
DF.add() does arithmetic between a DataFrame and another object. Without the other object it raised a TypeError.

Step 2: Compare loc[] and loc():
loc is an indexer. An indexer is used with square brackets, like a list.
Round brackets make Python treat it as a call. Python raised a ValueError for DF.loc(2).

Step 3: See the correct form work:
The line DF.loc[2] = ['Amit', 75] on a two-row DataFrame gave a third row with label 2 and the values Amit and 75.

Step 4: Decide:
Only DF.loc[] adds a row by assigning to a new label.

Final Answer:
Option (2), DF.loc[].
Was this answer helpful?
0