Great! We can also use multiple conditions when filtering our DataFrames with the help of the logical operators AND (
&) and OR (
hospitals[(hospitals['State'] == 'WA') | (hospitals['State'] == 'PA')]
The expression above will show only those hospitals that are either in Pennsylvania (PA) or Washington (WA). Note that each condition is wrapped in parentheses.
Usually, it is more readable to assign each condition to a particular variable, for the sake of clarity. Suppose we want to get hospitals that are in South Carolina with a rating of 4 or better. We could write:
sc_hospitals = hospitals['State'] == 'SC'
good_hospitals = hospitals['Hospital overall rating'] > 3
hospitals[sc_hospitals & good_hospitals]