Boolean Indexing
🎬 Watch the 5:11 video of this topic ↓Boolean indexing is how you ask a DataFrame a question and keep only the rows that answer yes. It's the heart of real data analysis — "show me everyone who…".
1Filter by a condition
A comparison like df['IP Marks'] > 85 produces a True/False for every row. Put that back inside df[...] and only the True rows survive. Slide the threshold:
A condition turns into a True/False test for every row. Feed it back into df[...] and only the True rows survive.
Name | English | IP | Maths | |
|---|---|---|---|---|
ID 1 | Rinku | 65 | 89 | 72 |
ID 2 | Ritu | 77 | 83 | 69 |
ID 3 | Pankaj | 72 | 95 | 87 |
ID 4 | Ajay | 81 | 99 | 94 |
ID 5 | Aditya | 92 | 87 | 96 |
2One condition
3Combining conditions with & and |
Join conditions with & (and) or | (or). Each condition must be wrapped in its own parentheses — this trips up almost everyone.
& and |, not the Python words and/or — and wrap every condition in parentheses. df[df.a > 1 & df.b < 2] without brackets is a common bug.df[mask] keeps the True rows. Combine masks with &/| and parenthesise each part.What does df[df['Maths Marks'] > 90] return?
Which correctly filters rows where a > 1 AND b < 5?
DataFrame: Boolean Indexing and Iterating, in 5:11
One animated video of this topic, narrated. Watch it before the lessons for the big picture, or after them to revise.
🔊 Hindi mein sunna hai? Watch on YouTube with Hindi audio ↗(there, choose ⚙ Settings → Audio track → Hindi)