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

© 2026 BraveProgrammer. All rights reserved.

  1. Courses
  2. /
  3. Master Data Science with Python

Lesson 21 of 60 · python

Selecting & Filtering Data in Pandas

Duration: 20 minutes

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].

Previous: Writing Data: Exporting DataFramesNext: Handling Missing Data in Pandas