- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to delete a column from a Pandas DataFrame?
To delete a column from a Pandas DataFrame, we can simply use del df["column name"]
Steps
Create a two-dimensional, size-mutable, potentially heterogeneous tabular data, df.
Print the input DataFrame.
Delete a column, del df["z"].
Print the updated DataFrame, df.
Example
import pandas as pd df = pd.DataFrame( { "x": [5, 2, 1, 9], "y": [4, 1, 5, 10], "z": [4, 1, 5, 0] } ) print "Input DataFrame is:
", df del df["z"] print "After deleting column-z:
", df
Output
Input DataFrame is: x y z 0 5 4 4 1 2 1 1 2 1 5 5 3 9 10 0 After deleting column-z: x y 0 5 4 1 2 1 2 1 5 3 9 10
- Related Articles
- How to delete a column from Pandas DataFrame
- Python Pandas - How to delete a row from a DataFrame
- Python - How to select a column from a Pandas DataFrame
- How to sort a column of a Pandas DataFrame?
- How to shift a column in a Pandas DataFrame?
- How to get the list of column headers from a Pandas DataFrame?
- How to add column from another DataFrame in Pandas?
- How to rename column names in a Pandas DataFrame?
- Create a Pipeline and remove a column from DataFrame - Python Pandas
- Python Pandas – Remove numbers from string in a DataFrame column
- Select rows from a Pandas DataFrame based on column values
- Apply uppercase to a column in Pandas dataframe
- Python - Add a zero column to Pandas DataFrame
- How to delete a column of a dataframe using the ‘pop’ function in Python?
- Merge Pandas DataFrame with a common column

Advertisements