Pandas · Filter rows
Google Search Analytics
Course overviewGoogle Search · Filter and sort searches

Filter rows

Use Boolean conditions to keep matching rows and select the columns to return.

Step 1 of 3 · Learn

Keep matching rows

Comparing a column with a value creates a Boolean Series: one True or False for each row. Pass that condition to .loc[condition, columns] to keep matching rows and the requested columns.

indexnamescore
0Ari10
1Bo20
2Cam30
indexnamescore
2Cam30
Only 30 is greater than 20. The boundary value 20 is excluded.

Choose the boundary

> and < exclude the boundary; >= and <= include it. Use == to test equality and != to test inequality. A single = assigns a value instead of comparing it.

▷ Your turn

Return search_id and response_ms for searches taking more than 300 milliseconds. Exclude exactly 300. Preserve source row order and save the DataFrame as result.

LANGUAGEPython · Pandas

Loading Python and Pandas…

Run the code to see DataFrame results here.