Get startedGet started for free

Subsetting rows

A large part of data science is about finding which bits of your dataset are interesting. One of the simplest techniques for this is to find a subset of rows that match some criteria. This is sometimes known as filtering rows or selecting rows.

There are many ways to subset a DataFrame, perhaps the most common is to use relational operators to return True or False for each row, then pass that inside square brackets.

dogs[dogs["height_cm"] > 60]
dogs[dogs["color"] == "tan"]

You can filter for multiple conditions at once by using the "bitwise and" operator, &.

dogs[(dogs["height_cm"] > 60) & (dogs["color"] == "tan")]

homelessness is available and pandas is loaded as pd.

This exercise is part of the course

Data Manipulation with pandas

View Course

Hands-on interactive exercise

Have a go at this exercise by completing this sample code.

# Filter for rows where individuals is greater than 10000
ind_gt_10k = ____

# See the result
print(ind_gt_10k)
Edit and Run Code