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:
![](https://static.packt-cdn.com/products/9781787123137/graphics/assets/fb62f9b6-c29b-4a71-978f-6e6336e18e09.png)
The following uses the .pop() method to remove the Sector column:
![](https://static.packt-cdn.com/products/9781787123137/graphics/assets/53be0f67-d919-40dc-822d-66dcff712f2d.png)
The .pop() method has the benefit that it gives us the popped columns.
![](https://static.packt-cdn.com/products/9781787123137/graphics/assets/971b79a4-63bc-42d1-b3ca-1b9e417c2219.png)
The .drop() method can be used to remove both rows and columns. To use it to remove columns, specify axis=1:
![](https://static.packt-cdn.com/products/9781787123137/graphics/assets/f0b99182-2008-4368-a0bc-56b71c57a472.png)