How do I remove columns from a pandas DataFrame?
Key Takeaways
This video demonstrates how to remove columns and rows from a pandas DataFrame using the drop method, explaining the axis and inplace parameters.
Full Transcript
hello and welcome back to my video Q&A series about the Panda's library in Python so the question for today is how do I remove columns from a panda's data frame great question uh so the panda data frame is of course the primary unit of uh data storage in the pandas Library it's like uh rows and columns so how do I remove a column uh as always we are going to pull up an example data set and uh but first we need to import pandas as PD and then uh we're going to pull up the UFO data set a data set of uh UFO sightings or reported sightings and so we'll use the read CSV function and we'll pass it the URL of the data set bit. Le slash UFO reports okay so this creates a pandas data frame and uh we'll just look at the head as a reminder of what is in this data frame they're just UFO reports it has uh five columns and in case you're curious you can use the shape attribute and see that there are 18,2 41 rows that's what this is telling us anyway uh let's pretend that we don't care about the colors reported column so we want to get rid of it okay how do we do that well let's uh we'll just use the drop method which is a data frame method so you say ufo. drop and then we're just going to pass it as a string the name of the column we want to drop so colors reported now there are two more things I'm going to add here the first is the axis so I'm going to say axis equals 1 and we'll talk more about axes in in another video but um in brief an axis is just kind of a direction okay so axis zero is the row axis um it kind of is a d like directionally like down is Axis zero I think of it is the row axis a AIS one is the column axis it's the one that kind of moves across and that movement will make more sense uh when we talk um more about it in a future video but axis equals 1 is the way I say to pandas I want to drop a column and its name is colors reported okay one more thing we're going to say in place equals true what does that mean uh it just means I want this operation to occur in place okay so uh we will run this and uh we will just rerun the head method and you will see that the colors reported column AKA series is now missing it's now gone okay so um you can actually drop multiple columns at once uh so I'll show you how to do that now so let's say I wanted to get rid of city and state I didn't care about those let's do ufo. drop and what you do is very similar except you just instead of passing a string you pass a list of strings okay so I'll say City uh whoops comma State okay so the first argument is that list the second argument is X is equal 1 third argument in place equals true we run that and UFO do head is now down to those two columns okay they are gone they are no longer part of the data frame and that's really it okay as always I like to end these videos with a bonus tip and the bonus tip is uh what if you want to remove uh rows instead of columns Well turns out you just use the drop method except you use axis zero cuz as I said axis one is the column axis axis zero is the row axis okay so uh so we're going to use ufo. drop and we know there's going to be something here and then we're going to say axis equals Zer and in place equals true but what is this first thing let's say I want to drop uh rows the first two rows because I don't care about UFO reports before 19 18 31 so I don't care about these two rows I don't want them in the data set so how do I refer to them um by name I actually the names are right here the names are zero and one okay just like these are the names of the columns these are the names of the rows they're uh officially called the index uh also called the labels and so I'm just going to pass a list and I'll just say Z comma 1 run that ufo. head and you you can see those two rows the 1930s have been dropped and if you really want to be sure that they're gone you can see that the shape uh the number of rows has decreased by two rows okay so uh one final note about this axis equals z is actually the default so technically I did not have to specify axis equals Z here uh however I always like to specify the axis just to be really clear about what I am doing okay so that's all for today thanks as always for joining me uh please click subscribe if you'd like to see more videos like this as always leave a comment uh telling me your question about this video or your Panda's question in general I will uh try to answer it maybe I'll even make a video okay so that's it uh thanks again and I will see you again soon
Original Description
If you have DataFrame columns that you're never going to use, you may want to remove them entirely in order to focus on the columns that you do use. In this video, I'll show you how to remove columns (and rows), and will briefly explain the meaning of the "axis" and "inplace" parameters.
SUBSCRIBE to learn data science with Python:
https://www.youtube.com/dataschool?sub_confirmation=1
JOIN the "Data School Insiders" community and receive exclusive rewards:
https://www.patreon.com/dataschool
== RESOURCES ==
GitHub repository for the series: https://github.com/justmarkham/pandas-videos
"drop" documentation: http://pandas.pydata.org/pandas-docs/stable/generated/pandas.DataFrame.drop.html
== LET'S CONNECT! ==
Newsletter: https://www.dataschool.io/subscribe/
Twitter: https://twitter.com/justmarkham
Facebook: https://www.facebook.com/DataScienceSchool/
LinkedIn: https://www.linkedin.com/in/justmarkham/
Watch on YouTube ↗
(saves to browser)
Sign in to unlock AI tutor explanation · ⚡30
Playlist
Uploads from Data School · Data School · 27 of 60
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
▶
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
Setting up Git and GitHub
Data School
Navigating a GitHub Repository - Part 1
Data School
Forking a GitHub Repository
Data School
Creating a New GitHub Repository
Data School
Copying a GitHub Repository to Your Local Computer
Data School
Committing Changes in Git and Pushing to a GitHub Repository
Data School
Syncing Your GitHub Fork
Data School
Allstate Purchase Prediction Challenge on Kaggle
Data School
Troubleshooting: Updates Rejected When Pushing to GitHub
Data School
Hands-on dplyr tutorial for faster data manipulation in R
Data School
ROC Curves and Area Under the Curve (AUC) Explained
Data School
Going deeper with dplyr: New features in 0.3 and 0.4 (tutorial)
Data School
What is machine learning, and how does it work?
Data School
Setting up Python for machine learning: scikit-learn and Jupyter Notebook
Data School
Getting started in scikit-learn with the famous iris dataset
Data School
Training a machine learning model with scikit-learn
Data School
Comparing machine learning models in scikit-learn
Data School
Data science in Python: pandas, seaborn, scikit-learn
Data School
Selecting the best model in scikit-learn using cross-validation
Data School
How to find the best model parameters in scikit-learn
Data School
How to evaluate a classifier in scikit-learn
Data School
What is pandas? (Introduction to the Q&A series)
Data School
How do I read a tabular data file into pandas?
Data School
How do I select a pandas Series from a DataFrame?
Data School
Why do some pandas commands end with parentheses (and others don't)?
Data School
How do I rename columns in a pandas DataFrame?
Data School
How do I remove columns from a pandas DataFrame?
Data School
How do I sort a pandas DataFrame or a Series?
Data School
How do I filter rows of a pandas DataFrame by column value?
Data School
How do I apply multiple filter criteria to a pandas DataFrame?
Data School
Your pandas questions answered!
Data School
How do I use the "axis" parameter in pandas?
Data School
How do I use string methods in pandas?
Data School
How do I change the data type of a pandas Series?
Data School
When should I use a "groupby" in pandas?
Data School
How do I explore a pandas Series?
Data School
How do I handle missing values in pandas?
Data School
What do I need to know about the pandas index? (Part 1)
Data School
What do I need to know about the pandas index? (Part 2)
Data School
How do I select multiple rows and columns from a pandas DataFrame?
Data School
Machine Learning with Text in scikit-learn (PyCon 2016)
Data School
When should I use the "inplace" parameter in pandas?
Data School
How do I make my pandas DataFrame smaller and faster?
Data School
How do I use pandas with scikit-learn to create Kaggle submissions?
Data School
More of your pandas questions answered!
Data School
How do I create dummy variables in pandas?
Data School
How do I work with dates and times in pandas?
Data School
How do I find and remove duplicate rows in pandas?
Data School
How do I avoid a SettingWithCopyWarning in pandas?
Data School
How do I change display options in pandas?
Data School
How do I create a pandas DataFrame from another object?
Data School
How do I apply a function to a pandas Series or DataFrame?
Data School
Getting started with machine learning in Python (webcast)
Data School
Q&A about Machine Learning with Text (online course)
Data School
Your pandas questions answered! (webcast)
Data School
Machine Learning with Text in scikit-learn (PyData DC 2016)
Data School
Write Pythonic Code for Better Data Science (webcast)
Data School
Web scraping in Python (Part 1): Getting started
Data School
Web scraping in Python (Part 2): Parsing HTML with Beautiful Soup
Data School
Web scraping in Python (Part 3): Building a dataset
Data School
More on: Data Literacy
View skill →Related AI Lessons
⚡
⚡
⚡
⚡
The AI Moat Paradox: The Better Models Become, the Less Models Matter
Medium · AI
170,927 AI Papers Reveal the Biggest Research Shifts of the First Half of 2026
Medium · Machine Learning
170,927 AI Papers Reveal the Biggest Research Shifts of the First Half of 2026
Medium · Data Science
[PoV] When Everyone Is Smart, No One Is
Medium · AI
🎓
Tutor Explanation
DeepCamp AI