Written and maintained by CASRAI Editorial Board
Last updated
To drop columns in pandas, call DataFrame.drop with the columns argument and assign the result to a variable: df = df.drop(columns=['B', 'C']). It returns a new DataFrame without those columns and leaves the original unchanged unless you ask otherwise. This guide covers drop(), dropna() for removing columns that contain missing values, and pop() for removing a column while keeping its values. The commands below are taken from the pandas 3.1.0 documentation, checked on 2026-10-29.
What it is used for in research
Analysis datasets often arrive with more columns than a study needs: identifiers that must not travel with the data, free-text fields, export artefacts, or variables outside the analysis plan. Dropping them is a routine step of data cleaning and data wrangling, and it usually comes early in an exploratory data analysis in Python. Because the operation changes which variables your results are based on, write it as an explicit line in your analysis script rather than deleting columns by hand in a spreadsheet, so anyone rerunning the script can see exactly what was removed.
Install or access
pandas is installed from the official package channels. The pandas installation page (pandas.pydata.org/docs/getting_started/install.html) lists:
pip install pandasconda install -c conda-forge pandas
Then import it in your script or notebook with import pandas as pd.
Step-by-step: drop columns
The examples use the DataFrame from the pandas documentation for DataFrame.drop:
import numpy as np
import pandas as pd
df = pd.DataFrame(np.arange(12).reshape(3, 4), columns=['A', 'B', 'C', 'D'])
1. Drop one or several columns by name
- Pass the names to the
columnsargument:df.drop(columns=['B', 'C']). - The documentation states that
labels, axis=1is equivalent tocolumns=labels, sodf.drop(['B', 'C'], axis=1)gives the same result. The default isaxis=0, which is whyaxis=1(or'columns') is needed when you use the positional form. - Assign the result:
df = df.drop(columns=['B', 'C']). The default behaviour ofdrop()is to return a copy.
For a single column, pass one name: df.drop(columns='B').
2. Drop rows and columns in one call
The signature accepts both index and columns, so one call can remove rows and columns together, for example df.drop(index='cow', columns='small') as in the documentation’s MultiIndex example.
3. Drop columns that contain missing values with dropna()
When the rule is "remove any column with missing data" rather than a list of names, use DataFrame.dropna with axis='columns' (or axis=1):
df = df.dropna(axis='columns')
how='any'(the default) drops a column if any value is missing;how='all'drops it only if every value is missing.threshsets the number of non-missing values a column needs to be kept. It cannot be combined withhow.subsetrestricts which labels are checked.
In the documentation’s example, df.dropna(axis='columns') leaves only the name column, because the toy and born columns each contain a missing value. Check how much data a rule would remove before you apply it; see NumPy NaN for how missing values are represented.
4. Remove a column and keep its values with pop()
DataFrame.pop(item) returns the item and drops it from the DataFrame. The returned object is the column as a Series, so it suits splitting a target variable from the features: y = df.pop('class'). Like drop(), it raises a KeyError if the column is not found.
Output and how to read it
With the example DataFrame, df.drop(['B', 'C'], axis=1) and df.drop(columns=['B', 'C']) both return a DataFrame with columns A and D and three rows:
| Row | A | D |
|---|---|---|
| 0 | 0 | 3 |
| 1 | 4 | 7 |
| 2 | 8 | 11 |
Check the result with df.columns or df.shape rather than assuming the call worked. If the columns are still there, you called drop() without assigning the returned DataFrame.
Troubleshooting
Why do I get a KeyError?
The documentation says drop() raises a KeyError if any of the labels is not found in the selected axis. Check spelling, capitalisation and stray whitespace in the names (print(df.columns.tolist())). If a column may legitimately be absent, for example when you rerun a script on a file with different exports, pass errors='ignore': the documentation says this suppresses the error and drops only the labels that exist. Leave the default (errors='raise') when a missing column would mean something is wrong, so the script fails loudly.
Why did my columns not disappear?
By default drop() returns a copy and the original DataFrame is unchanged. Assign the result back: df = df.drop(columns=[...]).
Why does inplace=True give me None?
With inplace=True, drop() modifies the DataFrame and returns None, so df = df.drop(columns=['B'], inplace=True) replaces your DataFrame with None. More importantly, the pandas 3.1.0 documentation lists the inplace parameter as deprecated since version 3.1.0 and to be removed in pandas 4.0. Use the assignment form df = df.drop(columns=[...]), which works in current versions and does not depend on the removed parameter.
Why is my tuple treated as one column?
The documentation states that a tuple passed as labels is used as a single label and not treated as an iterable. This matters with MultiIndex columns, where a tuple names one column. To drop several columns, pass a list.
Which method should I use?
| You want to | Use | Source |
|---|---|---|
| Remove columns you can name | df.drop(columns=[...]) |
pandas DataFrame.drop reference |
| Remove columns that contain missing values | df.dropna(axis='columns'), optionally with how or thresh |
pandas DataFrame.dropna reference |
| Remove a column and keep it as a Series | df.pop('name') |
pandas DataFrame.pop reference |
| Skip labels that may not exist | df.drop(columns=[...], errors='ignore') |
pandas DataFrame.drop reference |
If you need to change column names rather than remove them, see how to rename columns in a pandas DataFrame.
Free alternatives
The same operation in other open-source data tools, per their own documentation (checked 2026-10-29):
| Tool | Drop columns | Documented behaviour |
|---|---|---|
| Polars (Python) | df.drop('ham'), df.drop(['bar', 'ham']) or df.drop('foo', 'ham') |
Accepts column names or selectors; strict=True by default raises an exception if a name does not exist in the schema |
| R, dplyr | select(!c(Sepal.Length, Petal.Length)) |
The ! operator negates a selection, so the listed columns are removed |
FAQ
How do I drop multiple columns in pandas?
Pass a list to columns: df = df.drop(columns=['B', 'C']).
What is the difference between axis=1 and columns=?
None in result. The documentation states labels, axis=1 is equivalent to columns=labels; columns= is easier to read because it says what is being dropped.
Should I still use inplace=True?
No. It is documented as deprecated since pandas 3.1.0 and scheduled for removal in 4.0. Assign the returned DataFrame instead.
How do I drop columns with missing values?
Use df.dropna(axis='columns'), and add how='all' or thresh if dropping on any missing value is too aggressive.
How do I drop a column only if it exists?
Use df.drop(columns=['B'], errors='ignore').
Sources
- pandas documentation (version 3.1.0), DataFrame.drop, checked 2026-10-29.
- pandas documentation, DataFrame.dropna, checked 2026-10-29.
- pandas documentation, DataFrame.pop, checked 2026-10-29.
- pandas documentation, Installation, checked 2026-10-29.
- Polars documentation, polars.DataFrame.drop, checked 2026-10-29.
- dplyr documentation, select(), checked 2026-10-29.







