We're sorry but this app doesn't work properly without JavaScript enabled. Please enable it to continue.

This lesson's interactive features are locked, please to keep using them

The Not Operator

What about negating a boolean mask? In Pandas, you use the ~ operator, though direct comparisons can still use !=.

# Tracks that are NOT available
unavailable = df[~(df["status"] == "available")]

# Available tracks that are NOT in the US market
available_not_us = df[(df["status"] == "available") & ~(df["market"] == "US")]

The ~ flips boolean values – True becomes False and vice versa.

Just like & and |, wrap the thing you're negating in parentheses: ~(df["market"] == "US"). It keeps the precedence unambiguous.

Assignment

The West Coast SnackStack team wants to monitor every device outside their own region – but only the ones that are still reachable.

Complete the get_devices_outside_region function. It accepts a DataFrame of devices and a region, and returns only the devices outside that region that are still online.