How to remove the first column in a Pandas DataFrame? (with Examples)

There are several easy ways to delete the first column of your Pandas DataFrame. This is specially handy when wrangling your data after acquiring it from an external csv file, database, API etc’.

How to drop your DataFrame first column in Pandas?

Use the DataFrame pandas drop() to quickly drop the first column of your DataFrame. Make sure to specify the column/s names to remove and set the axis parameter to 1, to indicate that you will be dropping a column. For example. assuming that your DataFrame name is mydf, you can delete the first col using this snippet:

mydf.drop(columns = 'label_first_column', axis = 1, inplace= True)

Here are additional few options you might want to look into

Option 1:

Using the column index:

mydf.drop(columns = mydf.columns[0], axis = 1, inplace= True)

Option 2:

You can use the iloc accessor, as shown below:

mydf = mydf.iloc[:,1:]

Option 3:

You can use the DataFrame pop method:

mydf = mydf.pop('label_first_column')

Remove first column from DataFrame – Example

Create the DataFrame

We will get started by importing the pandas library and creating a simple DataFrame.

import pandas as pd

# define data
month = ['June', 'December', 'May', 'September']
language = ['Scala', 'SQL', 'Go', 'Python']
interviews = (84, 75, 79, 87)
hr = dict(month=month, language=language, interviews=interviews)
hrdf = pd.DataFrame(data=hr)


Here’s our initial DataFrame. We’ll go ahead and show you how to remove the month column.


Drop first column by label

hrdf.drop(columns = 'month', axis = 1, inplace=True)

Note: use the inplace=True parameter to persist your changes to your DataFrame.

Delete first column by index

In this case we pass column index 0 (corresponds to the leftmost column of our data).

hrdf.drop(columns = hrdf.columns[0], axis = 1, inplace=True)

Using the iloc indexer

hrdf = hrdf.iloc[:,1:]

Using the loc indexer


Using the Dataframe pop method


All methods above will provide the same result:


Drop multiple columns by index

What if instead of skipping one column, you would like to drop an arbitrary number of multiple columns? Here we go:

# pass a list of column indices to delete.
cols = hrdf.columns[[0,2]]
hrdf = hrdf.drop(columns = cols)

Remove first column without a name

When importing csv or Excel files, we typically get DataFrame with unnamed columns. In this case we might choose to drop the first unnamed column (or any of them):

unnamed_cols  =  hrdf.columns.str.contains('Unnamed')
hrdf = hrdf.drop(columns = unnamed_cols[0], inplace=True )

Related: How to drop columns with no name in Pandas?

Remove last column in pandas

Here’s how to delete the last column off your DataFrame:

hrdf.drop(columns = hrdf.columns[-1], axis = 1, inplace=True)

Related: Drop the left column of your R DataFrame

Delete the index in Pandas DataFrames

You are able to use the set_index DataFrame method, to define one of your columns as the DataFrame index. In this example, we’ll set the language column as index.