Boolean Indexing
Boolean indexing lets you filter rows based on conditions. This is one of the most powerful features of Pandas.
Basic Boolean Filtering
Create a boolean mask and use it to filter:
Loading Pandas Playground...
Direct Condition in Brackets
You can put the condition directly in brackets:
Loading Pandas Playground...
Multiple Conditions
Combine conditions with & (and), | (or), ~ (not):
Loading Pandas Playground...
String Conditions
Filter based on string content:
Loading Pandas Playground...
Using isin() for Multiple Values
Check if values are in a list:
Loading Pandas Playground...
Exercise: Filter by Condition
Loading Exercise...
Exercise: Multiple Conditions
Loading Exercise...
Key Points
- Boolean indexing:
df[condition] - Combine with
&(and),|(or),~(not) - Always wrap conditions in parentheses
.str.contains()for string matching.isin([])for checking multiple values- Returns a new DataFrame (doesn't modify original)

