Ampersand vs And

,

Screen Link:
https://app.dataquest.io/m/22/introduction-to-evaluating-binary-classifiers/4/binary-classification-outcomes 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