Given the following series 'ser1':
0 69 1 80 2 20 3 50 4 100 5 70
State the output of the following command:
print(ser1>=70)
Given the following series 'ser1':
| 0 | 69 |
|---|---|
| 1 | 80 |
| 2 | 20 |
| 3 | 50 |
| 4 | 100 |
| 5 | 70 |
State the output of the following command:
print(ser1>=70)
Solution
Comparing a pandas Series with a number gives a Series of Boolean values, one for each element, with the same index. Nothing is filtered out. Here the values are 69, 80, 20, 50, 100 and 70, and the test is :
| Index | Value | |
|---|---|---|
| 0 | 69 | False |
| 1 | 80 | True |
| 2 | 20 | False |
| 3 | 50 | False |
| 4 | 100 | True |
| 5 | 70 | True |
Option 2 shows this Boolean Series with all six rows, using F and T as shorthand for False and True. Real pandas output prints the full words and ends with dtype: bool.
Options 1 and 4: these show the filtered values, which you get from ser1[ser1>=70]. The bare comparison does not filter.
Option 3: it keeps only the True rows, which is wrong because the comparison returns every index, including the False ones.
Related questions:
2026: 21 May Shift 1
2025: 21 May Shift 1
2026: 23 May Shift 2
2026: 23 May Shift 1
2025: 27 May Shift 2