How to Delete Columns in a Pandas DataFrame

One of the most common tasks I perform daily is removing unnecessary data from my DataFrames.

Whether I am working with US Census data or Wall Street stock prices, there is always extra “noise.”

In this tutorial, I will show you exactly how to delete columns in a Pandas DataFrame. I have tried every method available over the years, and I will share my firsthand experience on which ones work best.

Create a Sample DataFrame (US Fortune 500 Data)

Before we jump into the methods, let’s create a dataset we can work with. I will use a small sample of US-based tech companies and their financial data.

import pandas as pd

# Creating a dataset of US Tech Companies
data = {
    'Company': ['Apple', 'Microsoft', 'Alphabet', 'Amazon', 'Meta'],
    'Ticker': ['AAPL', 'MSFT', 'GOOGL', 'AMZN', 'META'],
    'HQ_State': ['California', 'Washington', 'California', 'Washington', 'California'],
    'Employees': [164000, 221000, 190234, 1541000, 86482],
    'Revenue_Billion': [394.3, 198.3, 282.8, 514.0, 116.6],
    'Founding_Year': [1976, 1975, 1998, 1994, 2004]
}

df = pd.DataFrame(data)
print("Original DataFrame:")
print(df)

You can see the output in the screenshot below.

Delete Columns in a Pandas DataFrame

In the examples below, I will show you how to remove columns like ‘HQ_State’ or ‘Founding_Year’ when they aren’t needed.

Method 1: Use the drop() Method (By Column Name)

In my experience, the drop() method is the most reliable way to remove columns. It is very explicit, which makes your code easier for other developers to read later.

To delete a single column, you simply pass the name of the column and set the axis parameter to 1.

# Removing the 'Founding_Year' column
df_updated = df.drop('Founding_Year', axis=1)

print(df_updated)

I usually prefer using the columns parameter instead of axis=1 because it is more intuitive.

# An alternative way that I find cleaner
df_updated = df.drop(columns=['HQ_State'])

print(df_updated)

One thing I have learned is to be careful with the inplace=True parameter.

If you set it to True, it modifies your original DataFrame and you cannot undo the change easily.

Method 2: Delete Multiple Columns at Once

Often, I find myself needing to clean up five or six columns at the same time. You can do this easily by passing a list of column names to the drop() method.

Let’s say we only want to keep the Company, Ticker, and Revenue for our US stock analysis.

# Dropping multiple columns in one go
cols_to_remove = ['HQ_State', 'Employees', 'Founding_Year']
df_cleaned = df.drop(columns=cols_to_remove)

print(df_cleaned)

I always suggest creating a list variable for your column names first if the list is long. This keeps your code organized and makes it much easier to debug if a name is misspelled.

Method 3: Use the del Keyword

If I am working in a Jupyter Notebook and want to quickly remove a column in place, I use del.

It is a standard Python command that deletes the column directly from the DataFrame.

# Using del to remove the 'Ticker' column
del df['Ticker']

print(df)

I don’t recommend using this in large production scripts because it is not “functional” in nature. Unlike drop(), it doesn’t return a new DataFrame; it changes the one you have immediately.

Method 4: Use the pop() Method

The pop() method is quite unique, and I use it when I want to “cut” a column out and move it elsewhere.

When you use pop(), it removes the column from the DataFrame but returns it as a Series.

I find this very useful when I want to isolate a target variable for a machine learning model.

# Popping the Revenue column to use it separately
revenue_series = df.pop('Revenue_Billion')

print("Remaining DataFrame:")
print(df)

print("\nExtracted Revenue Series:")
print(revenue_series)

You can see the output in the screenshot below.

How to Delete Columns in a Pandas DataFrame

It is a great way to “kill two birds with one stone” by cleaning the data and saving a part of it.

Method 5: Delete Columns by Index (Position)

Sometimes, I work with datasets where the column names are messy or contain strange characters.

In these cases, I find it easier to delete columns by their numerical position.

You can do this by using the df.columns index within the drop() method.

# Dropping the first and third columns (index 0 and 2)
df_indexed = df.drop(df.columns[[0, 2]], axis=1)

print(df_indexed)

I usually avoid this method if the source data structure might change. If a new column is added at the start of your file, your index-based code will delete the wrong data.

Method 6: Drop Columns Based on Conditions

In my larger projects, I often need to drop columns that have too many missing values.

If I am analyzing US real estate data and a column is 90% empty, I don’t want it in my analysis.

You can use the dropna() method specifically for columns.

import numpy as np

# Adding a column with null values for the example
df['Notes'] = [np.nan, 'Top Tier', np.nan, np.nan, 'Growth']

# Dropping any column that has at least one null value
df_no_nas = df.dropna(axis=1)

print(df_no_nas)

You can see the output in the screenshot below.

Delete Columns in Pandas DataFrame

I often use this to keep my DataFrames lean and focused only on the variables that have complete data.

Handle “KeyError” When Deleting Columns

One mistake I made frequently in my early days was trying to delete a column that didn’t exist. This happens a lot if you accidentally run a code cell twice in a row.

To prevent your script from crashing, you can check if the column exists before dropping it.

column_to_delete = 'Market_Cap'

if column_to_delete in df.columns:
    df.drop(columns=[column_to_delete], inplace=True)
else:
    print(f"The column {column_to_delete} was not found, so I skipped it.")

I have found that adding these small checks saves me a lot of headaches during long data processing runs.

Performance Tip for Large DataFrames

When I am working with millions of rows of US logistics data, performance matters. Reassigning a DataFrame (like df = df.drop(…)) creates a copy in memory.

If your DataFrame is several gigabytes, this might slow down your computer or cause an error. In those specific cases, using inplace=True or del is actually better for memory management.

However, for most daily tasks, the standard drop() method is more than enough. Deleting columns is one of the first steps in any data cleaning workflow I perform.

Using the drop() method with column names is generally the best approach for most Python developers. It is clear, readable, and handles multiple columns very efficiently.

If you are building a data pipeline, I suggest sticking to drop() to keep your code professional and easy to maintain.

You may also like to read:

51 Python Programs

51 PYTHON PROGRAMS PDF FREE

Download a FREE PDF (112 Pages) Containing 51 Useful Python Programs.

pyython developer roadmap

Aspiring to be a Python developer?

Download a FREE PDF on how to become a Python developer.

Let’s be friends

Be the first to know about sales and special discounts.