Ampersand vs And


Screen Link: Part 1

My Code:

true_positives = sum((admissions["predicted_label"] == 1) & (admissions["actual_label"] == 1))

Why can the and not be used in the place of the ampersand?

Because that’s how pandas was designed. and and or are python’s logical operators while & and | are pandas’ logical operators, designed to work with Series in a vectorized manner.

This Stack Overflow question can provide more information.

1 Like