Match both conditions
Use & when both conditions must be true. Put each comparison in parentheses; Python's and does not combine two Pandas Boolean Series.
| index | team | score |
|---|---|---|
| 0 | A | 10 |
| 1 | B | 30 |
| 2 | A | 30 |
| index | team | score |
|---|---|---|
| 2 | A | 30 |
Combine row-level conditions with AND, OR, and NOT using Pandas Boolean operators.
Step 1 of 3 · Learn
Use & when both conditions must be true. Put each comparison in parentheses; Python's and does not combine two Pandas Boolean Series.
| index | team | score |
|---|---|---|
| 0 | A | 10 |
| 1 | B | 30 |
| 2 | A | 30 |
| index | team | score |
|---|---|---|
| 2 | A | 30 |
Use | when either condition can match. Group an OR expression before combining it with another condition, so the extra condition applies to both alternatives.
| index | team | score |
|---|---|---|
| 0 | A | 10 |
| 1 | B | 20 |
| 2 | C | 30 |
| index | team | score |
|---|---|---|
| 0 | A | 10 |
| 1 | B | 20 |
Use ~ to reverse a Boolean condition. Parentheses make clear which condition is being reversed; ~ is not Python's scalar not operator.
| index | team | score |
|---|---|---|
| 0 | A | 10 |
| 1 | B | 20 |
| 2 | C | 30 |
| index | team | score |
|---|---|---|
| 0 | A | 10 |
| 2 | C | 30 |
Return search_id, device, and response_ms for mobile searches taking more than 300 milliseconds. Both conditions must match. Preserve source row order and save the DataFrame as result.
Loading Python and Pandas…
Run the code to see DataFrame results here.