On the basis of the following series 'ser1', state the output of the command that follows:
ser1
a 100 b 900 c 700 d 200 e 500
print(ser1[ser1>700])
On the basis of the following series 'ser1', state the output of the command that follows:
ser1
| a | 100 |
|---|---|
| b | 900 |
| c | 700 |
| d | 200 |
| e | 500 |
print(ser1[ser1>700])
Solution
ser1>700 builds a Boolean series that is True only where the value is greater than 700. Here that is only b (900), since c is exactly 700 and the condition is strictly greater than.
Passing this Boolean series back into ser1[...] keeps only the True entries, with their original index labels. The output is the single row b 900.
Option 1: includes c (700), which would only appear for ser1>=700.
Option 2: this is the output of print(ser1>700) alone, which gives the Boolean series. But in this option, e is shown as True although 500 is not greater than 700, so it is wrong in any case.
Option 4: the index label is not reset to a number, so the original label b is kept.
Related questions:
2025: 13 May Shift 2
2026: 31 May Shift 1
2026: 23 May Shift 1
2025: 16 May Shift 1