Skip to main contentSkip to solution

Consider a DataFrame 'df' given below.

SubjectAmitAshuAtulArnab
Maths80858290
Science75707983
Hindi82848878
English80707981

Which of the following statement will display name of the student and True or False depending on satisfying the condition of student having scored more than 90 in Maths?

Solution

✅ Correct Option: 2

df.loc['Maths'] selects the row labelled Maths, giving a Series whose index is the student names (Amit, Ashu, Atul, Arnab). Applying > 90 to it compares each mark with 90 and returns a Series of True/False values, one per student name.

Here every value is False, because the highest Maths score is 90 (Arnab), which is not more than 90.


Options 3 and 4: df['Maths'] looks for a column named Maths. Maths is a row label, so this raises a KeyError.

Option 1: this passes the True/False Series (indexed by student names) inside df[...] as a filter. It does not just display True/False per student, and it does not match the row labels.

Remember: df['label'] selects a column, while df.loc['label'] selects a row.

Keyboard Shortcuts

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