You are right, it is difference and I think there is problem with priority of operators - check docs:
df = pd.DataFrame({'col1':[True, False, False, False],
'col2':[4, np.nan, np.nan, 1]})
print (df)
col1 col2
0 True 4.0
1 False NaN
2 False NaN
3 False 1.0
# operator & precedence
print (df[df.col1 == False & df.col2.isnull()])
col1 col2
1 False NaN
2 False NaN
3 False 1.0
# operator == precedence bacause in brackets
print (df[(df.col1 == False) & (df.col2.isnull())])
col1 col2
1 False NaN
2 False NaN
It seems I found it in docs - 6.16. Operator precedence where see &
have higher priority as ==
:
Operator Description
lambda Lambda expression
if – else Conditional expression
or Boolean OR
and Boolean AND
not x Boolean NOT
in, not in, is, is not, Comparisons, including membership tests
<, <=, >, >=, !=, == and identity tests
| Bitwise OR
^ Bitwise XOR
& Bitwise AND
(expressions...), [expressions...], Binding or tuple display, list display,
{key: value...}, {expressions...} dictionary display, set display