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

Deleting columns

Columns can be deleted from a DataFrame by using the del keyword or the .pop() or .drop() method of the data frame. The behavior of each of these differs slightly:

  • del will simply delete the Series from the DataFrame (in-place)
  • pop() will both delete the Series and return the Series as a result (also in-place)
  • drop(labels, axis=1) will return a new data frame with the column(s) removed (the original DataFrame object is not modified)

The following demonstrates using del to delete the BookValue column from a copy of the sp500 data:

The following uses the .pop() method to remove the Sector column:

The .pop() method has the ...

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