Logical operation on two columns of a dataframe
Yes there is a better way! Just use the &
element-wise logical and operator:
d.bar & d.foo
0 True
1 False
2 False
dtype: bool
Also, there exists another one you could just multiply for AND or add for OR. Without the conversion and extra comparison as you had done.
AND operation:
d.foo * d.bar
OR operation:
d.foo + d.bar