Skip to main contentSkip to solution

SumitJyotiAsthaRakesh
Maths90856890
Physics92877587
Chemistry91797171
Computer Science88768488

A DataFrame 'df' is created as above. Which of the following syntax is the correct way for adding a row 'English' to this DataFrame?

Solution

✅ Correct Option: 3

df.loc['English'] = [67, 78, 89, 56] adds a new row. loc works with row labels, and assigning to a label that does not yet exist creates a new row with that label. The list has four values, matching the four columns (Sumit, Jyoti, Astha, Rakesh).


Options 2 and 4: iloc is purely position-based and accepts only integers, so a string label like 'English' raises an error. It also cannot create a new row.

Option 1: a DataFrame has no create attribute or method in pandas.

Remember: df.loc[label] = values adds a row, while df[label] = values adds a column.

Keyboard Shortcuts

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