
- Python Basic Tutorial
- Python - Home
- Python - Overview
- Python - Environment Setup
- Python - Basic Syntax
- Python - Comments
- Python - Variables
- Python - Data Types
- Python - Operators
- Python - Decision Making
- Python - Loops
- Python - Numbers
- Python - Strings
- Python - Lists
- Python - Tuples
- Python - Dictionary
- Python - Date & Time
- Python - Functions
- Python - Modules
- Python - Files I/O
- Python - Exceptions
Create a Pipeline and remove a column from DataFrame - Python Pandas
Use the colDrop() method of pdpipe library to remove a column from Pandas DataFrame. At first, import the required pdpipe and pandas libraries with their respective aliases −
import pdpipe as pdp import pandas as pd
Let us create a DataFrame. Here, we have two columns −
dataFrame = pd.DataFrame( { "Car": ['BMW', 'Lexus', 'Audi', 'Mustang', 'Bentley', 'Jaguar'],"Units": [100, 150, 110, 80, 110, 90] } )
To remove a column from the DataFrame, use the ColDrop() method. Here, we are removing the “Units” column −
resDF = pdp.ColDrop("Units").apply(dataFrame)
Example
Following is the complete code −
import pdpipe as pdp import pandas as pd # Create DataFrame dataFrame = pd.DataFrame( { "Car": ['BMW', 'Lexus', 'Audi', 'Mustang', 'Bentley', 'Jaguar'],"Units": [100, 150, 110, 80, 110, 90] } ) print("DataFrame ...\n",dataFrame) # removing a row with pdp dataFrame = pdp.ValDrop(['Jaguar'],'Car').apply(dataFrame) print("\n DataFrame after removing a row...\n",dataFrame) # removing a column with pdp resDF = pdp.ColDrop("Units").apply(dataFrame) print("\nDataFrame after removing a column...\n",resDF)
Output
This will produce the following output −
DataFrame ... Car Units 0 BMW 100 1 Lexus 150 2 Audi 110 3 Mustang 80 4 Bentley 110 5 Jaguar 90 Displaying after removing a row... Car Units 0 BMW 100 1 Lexus 150 2 Audi 110 3 Mustang 80 4 Bentley 110 Displaying after removing a column... Car 0 BMW 1 Lexus 2 Audi 3 Mustang 4 Bentley
- Related Articles
- Create a Pipeline and remove a row from an already created DataFrame - Python Pandas
- Python Pandas – Remove numbers from string in a DataFrame column
- Python - Create a Pipeline in Pandas
- Python – Create a new column in a Pandas dataframe
- Python - Remove duplicate values from a Pandas DataFrame
- Python - How to select a column from a Pandas DataFrame
- Python Pandas - Create Multiindex from dataframe
- Python Pandas - Create a DataFrame from DateTimeIndex but override the name of the resulting column
- Python Pandas - Create a DataFrame from DateTimeIndex ignoring the index
- How to delete a column from a Pandas DataFrame?
- How to delete a column from Pandas DataFrame
- Python - Add a zero column to Pandas DataFrame
- Python – Drop a level from a multi-level column index in Pandas dataframe
- Python Pandas - Create a DataFrame from the TimeDeltaIndex object but override the name of the resulting column
- Create a Pandas Dataframe from a dict of equal length lists in Python

Advertisements