I am "anding" a binary and non binary column in a pandas DataFrame. To my surprise, this actually gave a result (I was expecting an error). Take a look at the following code:
import pandas as pd
d = {'col1':[1,1,2,2,2], 'col2':[3,4,4,4,3]}
test_df = pd.DataFrame(data = d)
test_df['bool1'] = [True, False, True, True, False]
test_df['bool2'] = [True, False, True, True, True]
test_df['col3'] = [1,3,3,5,5]
test_df['col3'] & test_df['bool1']
I get the following result:
0 True
1 False
2 True
3 True
4 False
dtype: bool
How does pandas evaluate this? col3
is not boolean/binary so I have a hard time determining what drives the decision on whether the combination of both is True
or False
?