A previous tutorial showed you how to drop columns in a pandas dataframe. Now we will look at how to drop rows in a pandas dataframe.
There are multiple methods for how to drop rows in pandas dataframe.
We will once again work with Titanic data. Dropping rows in pandas are full of options. This doesn’t mean we will cover all of them, so if you have a question leave it below.
See the full code in our gist or skip to the end of this article.
The most basic way to drop rows in pandas is with axis=0
Here you drop two rows at the same time using pandas
titanic.drop([1, 2], axis=0)
Super simple approach to drop a single row in pandas
Drop specific items within a column in pandas
Here we will drop male from the sex column.
titanic[titanic.sex != 'male']
Drop multiple rows in pandas
This is how to drop a range of rows within pandas.
Enjoy the full code!