~ 1 min read

Remove Columns in Python Pandas

By: Adam Richardson
Share:

Intro

Now that you can add columns, let’s look at how to delete columns with Python Pandas.

Previous Post

Learn how to create and add new columns to a Pandas DataFrame using Python. In this tutorial, we will cover various methods to manipulate column data and explore the different ways to add columns to a DataFrame

Dropping Columns

You can use the drop method to delete one or more columns from a DataFrame. The drop method takes a list of column labels to be deleted as its first argument, and the axis parameter, which should be set to 1, to specify that columns are being deleted. The inplace parameter, if set to True, modifies the original DataFrame and does not return a new one.

Assigning to a new dataframe

This is how you can assign a new dataframe, note that we are reassigning to the df variable, which means we could also just do the deletion with inplace=True and achieve the same thing

df = df.drop(["literalOne", "brand"], axis=1)

With inplace=True

df.drop(["literalOne", "brand"], axis=1, inplace=True)

Instead of deleting or removing columns, perhaps you can just select a subset of columns. Learn how in our next post.

Share:
Subscribe to our newsletter

Stay up to date with our latest content - No spam!

Related Posts