Question:

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
collegedunia
Verified By Collegedunia

The Correct Option is B

Solution and Explanation

Step 1: Think about what the task needs:
We want to add a new row to an existing DataFrame DF.
The easy way is to give the row label and assign values to it.

Step 2: Test the loc way:
df = pd.DataFrame({'Name': ['Ravi', 'Sita'], 'Marks': [80, 90]})
df.loc[2] = ['Amit', 75]
print(df)

The run printed:
Name Marks
0 Ravi 80
1 Sita 90
2 Amit 75
A new row with label 2 was added.

Step 3: Check option (2) DF.loc[]:
It uses square brackets and a new label, so it adds the row. (2) is correct.

Step 4: Check the wrong options:
(1) DF.add() is a method for adding values of two DataFrames. Calling it alone gave a TypeError, because it needs another argument.
(3) DF.loc() uses round brackets. loc is not called like a function. The run gave a ValueError.
(4) DF.addloc[] does not exist. The run gave an AttributeError.

Final Answer:
A new row is added with DF.loc[], option (2).
Was this answer helpful?
0
0