Join us and get access to thousands of tutorials and a community of expert Pythonistas.

Unlock This Lesson

This lesson is for members only. Join us and get access to thousands of tutorials and a community of expert Pythonistas.

Unlock This Lesson

Hint: You can adjust the default video playback speed in your account settings.
Hint: You can set your subtitle preferences in your account settings.
Sorry! Looks like there’s an issue with video playback 🙁 This might be due to a temporary outage or because of a configuration issue with your browser. Please refer to our video player troubleshooting guide for assistance.

Dropping Columns

00:00 As you’ve seen, the books dataset has a few columns that don’t have very much useful information. In this lesson, you’ll learn about dropping columns. That is, how to delete columns from a DataFrame.

00:13 So you want to drop columns. Removing is actually called dropping in pandas. You can use the conveniently named .drop() method. You’ll also understand what axes refer to when you’re using this method.

00:29 Continuing the method-chaining method here, going to called .drop() on the end. And what you can pass in is an argument called columns and a list of all the column titles that you want to drop, basically.

00:53 I’m going to just copy this from here, paste it into here.

01:03 This would currently drop everything. However, we don’t want to drop everything. We want the id. So we don’t want the edition_statement.

01:12 We want the place, the publisher, the title, the author, the contributors. We’re not interested in corporate, former, engraver, issuance type. The flickr_url we do want. Okay, so that’s us.

01:25 So now, if we look at the columns left, you have the ones that you want. An alternative way that you might see this written is without the columns argument. However, it won’t know what you want these names to be.

01:41 So in this case, you say axis=1, which means columns. axis=0 means the rows. Or you can also put in "columns", and this will have the same effect.

01:58 That’s what the axis is referring to. However, since this is much more readable, you can just assign it like this.

02:18 In this lesson, you’ve successfully dropped some columns from your DataFrame. In the next lesson, you’ll be looking a bit closer at indices and how to work with them.

Become a Member to join the conversation.