December 2018
Beginner to intermediate
682 pages
18h 1m
English
A consequence of pandas using different syntax for the logical operators is that operator precedence is no longer the same. The comparison operators have a higher precedence than and, or, and not. However, the new operators for pandas (the bitwise operators &, |, and ~) have a higher precedence than the comparison operators, thus the need for parentheses. An example can help clear this up. Take the following expression:
>>> 5 < 10 and 3 > 4False
In the preceding expression, 5 < 10 evaluates first, followed by 3 < 4, and finally, the and evaluates. Python progresses through the expression as follows:
>>> 5 < 10 and 3 > 4>>> True and 3 > 4>>> True and False>>> False
Let's take a look at what would happen if the expression in ...