Skip to main contentSkip to solution

Consider the following DataFrame named "marks":

ArnabSumitSonam
Maths847885
Science868486
Hindi789594

Which of the following option is correct to insert the record of another student named "Priya"?

Solution

✅ Correct Option: 4

In a pandas DataFrame, students are columns, so a new student is added as a new column. The syntax is df["column_name"] = values, which here is marks["Priya"]=[78,89,76]. The list has three values, one for each row (Maths, Science, Hindi).


Option 1: this reassigns the variable marks to a plain list and destroys the DataFrame.

Option 2: marks[2] uses an integer as the column label. This creates a column named 2, not "Priya", or raises an error.

Option 3: Priya without quotes is treated as a variable name, which is not defined, so it raises a NameError.

Keyboard Shortcuts

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