In this article, we will discuss how to drop columns in Pandas Dataframe by label Names or by Index Positions. Drop columns from a DataFrame can be achieved in multiple ways.
Let’s create a simple dataframe with a dictionary of lists, say column names are: ‘Name’, ‘Age’, ‘Place’, ‘College’.
Method 1: Drop Columns from a Dataframe using
Example 1: Remove specific single mention column.
Example 2 : Remove specific multiple mentions columns.
Example 3: Remove columns as based on column index.
Method 2: Drop Columns from a Dataframe using
Example: Remove all columns between a specific column to another columns(exclude)
Method 3: Drop Columns from a Dataframe using
Example: Remove all columns between a specific column name to another columns name.
iloc() is iloc() exclude last column range element.
Method 4: Drop Columns from a Dataframe by iterative way.
Example: Remove specific column.
Attention geek! Strengthen your foundations with the Python Programming Foundation Course and learn the basics.
To begin with, your interview preparations Enhance your Data Structures concepts with the Python DS Course. And to begin with your Machine Learning Journey, join the Machine Learning – Basic Level Course