I have two Series which have a format equal to this:
0    False
1    False
2    False
3    True
4    True
Name: foo, dtype: bool
0    True
1    False
2    False
3    True
4    True
Name: bar, dtype: bool
I want to create a new Series with the resulting boolean comparison from these. Something like this:
result = foo and bar
>>> print result
0    False
1    False
2    False
3    True
4    True
Name: result, dtype: bool
Using the obvious result = foo and bar simply results in the following error: 
ValueError: The truth value of a Series is ambiguous. Use a.empty, a.bool(), a.item(), a.any() or a.all().
I looked at those functions, but neither seem to do what I wish.
How can I do an element-to-element boolean comparison of a Series resulting in a new Series?
You need to use the bitwise and operator &.  
result = foo & bar
                        If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With