Consider the following DataFrame 'df':
Name Test English Maths Hindi Science Sumit 1 67 87 75 88 Sumit 2 76 78 72 82 Jyoti 1 77 83 60 87 Jyoti 2 69 89 68 65 Nidhi 1 56 78 65 69 Nidhi 2 67 86 89 91
Which statement results in marks secured by Jyoti in each subject in each test?
Consider the following DataFrame 'df':
| Name | Test | English | Maths | Hindi | Science |
|---|---|---|---|---|---|
| Sumit | 1 | 67 | 87 | 75 | 88 |
| Sumit | 2 | 76 | 78 | 72 | 82 |
| Jyoti | 1 | 77 | 83 | 60 | 87 |
| Jyoti | 2 | 69 | 89 | 68 | 65 |
| Nidhi | 1 | 56 | 78 | 65 | 69 |
| Nidhi | 2 | 67 | 86 | 89 | 91 |
Which statement results in marks secured by Jyoti in each subject in each test?
Solution
df['Name']=='Jyoti' gives a Boolean Series, True for rows where Name is Jyoti. Passing it inside df[...] selects only those rows with all their columns. So df[df['Name']=='Jyoti'] returns both of Jyoti's test rows, showing her marks in every subject for each test.
Option 1: the brackets are unbalanced, so it is a syntax error. It also never filters the DataFrame.
Option 3: df.loc['Name'] looks for a row labelled 'Name', not a column, so it raises a KeyError.
Option 4: ['Name']=='Jyoti' compares a plain list with a string, which gives the single value False, not a Boolean Series, so no rows are selected correctly.
Related questions:
2026: 23 May Shift 1
2026: 26 May Shift 1
2026: 23 May Shift 1
2025: 13 May Shift 2
2026: 24 May Shift 1