Delete rows/ columns in a Pandas DataFrame

The drop() method is used in Python to delete rows/ columns in a Pandas DataFrame. It is used to remove a particular row or column. Under the parameters of the drop() method, mention the column you want to delete with the axis.

We will now see two examples:

  1. Drop columns
  2. Drop rows

Drop columns using drop()

The columns are dropped using the column names. The axis is set to 1 since we want to drop a column. The columns axis can also be used for the drop() method to remove the specified column:

Let us see an example to drop columns using the drop() method:

Output

Drop rows using drop()

The rows are dropped using the index label set as a parameter of the drop() method. The rows of that particular label are removed. Set the axis to 0 since we want to drop a row. The rows axis i.e. index can also be used for the drop() method to remove the specified row:

Let us see an example of dropping a row using the drop() method. Here, the row with the 2nd index is removed:

Output


If you liked the tutorial, spread the word and share the link and our website Studyopedia with others.


For Videos, Join Our YouTube Channel: Join Now


 

Add a new column to Pandas DataFrame
Iterate over rows and columns in a Pandas DataFrame
Studyopedia Editorial Staff
Studyopedia Editorial Staff
[email protected]

We work to create programming tutorials for all.

No Comments

Post A Comment

Discover more from Studyopedia

Subscribe now to keep reading and get access to the full archive.

Continue reading