Consider a DataFrame 'df' given below.
Subject Amit Ashu Atul Arnab Maths 80 85 82 90 Science 75 70 79 83 Hindi 82 84 88 78 English 80 70 79 81
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?
Consider a DataFrame 'df' given below.
| Subject | Amit | Ashu | Atul | Arnab |
|---|---|---|---|---|
| Maths | 80 | 85 | 82 | 90 |
| Science | 75 | 70 | 79 | 83 |
| Hindi | 82 | 84 | 88 | 78 |
| English | 80 | 70 | 79 | 81 |
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
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.
Related questions:
2026: 13 May Shift 2
2025: 13 May Shift 2
2026: 24 May Shift 1