Question
How to perform bitwise operations in Pandas?
How it &works with integers
In integers, the operator &performs a bitmask
>>> mask = 0b1100
>>> 7 & mask
4
How it &works in Pandas
Is there a way to perform bitwise masking operations in Pandas? The operator &is doing something else.
>>> df = DataFrame([1, 2, 3, 4, 5, 6, 7, 8], columns=['data'])
>>> df.data & mask
0 False
1 False
2 False
3 True
4 True
5 True
6 True
7 True
Name: data, dtype: bool
source
share