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')