Skip to main content
Brave Programmer Logo

BraveProgrammer

BraveProgrammer

HomeProjectsBlogsCoursesLessonsAbout

Site footer

BraveProgrammer

Free coding courses, practical tutorials, and real projects from BraveProgrammer. Learn web development with React, Next.js, and TypeScript.

Navigation

  • Home
  • Projects
  • Blogs
  • Courses

Resources

  • About
  • Lessons
  • Teach on BraveProgrammer

© 2026 BraveProgrammer. All rights reserved.

Selecting & Filterin | Master Data Science with Python lesso | BraveProgrammer
  1. Courses
  2. /
  3. Master Data Science with Python

Lesson 21 of 60

·python

Selecting & Filtering Data in Pandas

20 minutes

Course progress35%

Selecting & Filtering Data

Pandas provides expressive syntax for subsetting.

Selecting rows by label with .loc

df.loc[10:20]   # rows with index 10‑20 inclusive

Selecting rows by integer location with .iloc

df.iloc[:3]    
# first three rows

Boolean indexing

df_filtered = df[df['age'] > 30]

Combining multiple conditions

mask = (df['salary'] > 50000) & (df['department'] == 'Engineering')
engineers = df[mask]

Using .query for SQL‑like syntax

df.query('salary > 80000 and age < 40')

Info

.loc works with both rows and columns: df.loc[row_slice, col_slice].
Make it stickPractice what you've learned1 quiz · 4 practical tests · Optional activities from Master Data Science with PythonBrowse activities
Previous lessonWriting Data: Exporting DataFramesContinue to lesson 22Handling Missing Data in PandasBack to Master Data Science with Python curriculum