O'Reilly logo

Learning pandas - Second Edition by Michael Heydt

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Removing rows using Boolean selection

Boolean selection can also be used to remove rows from a DataFrame. The result of a Boolean selection will return a copy of rows where the expression is True. To drop rows, simply construct an expression that returns False for the rows that are to be dropped and then apply the expression to the data frame.

The following demonstrates dropping rows where Price is greater than 300. First, construct the expression.

From this result, we now know that there are 10 rows where the price is greater than 300. To get a data frame with those rows removed, select the complement of the selection.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required