Sunday, September 28, 2025
HomeLanguagesDelete a column from a Pandas DataFrame

Delete a column from a Pandas DataFrame

Deletion is one of the primary operations when it comes to data analysis. Very often we see that a particular attribute in the data frame is not at all useful for us while working on a specific analysis, rather having it may lead to problems and unnecessary change in the prediction. For example, if we want to analyze the students’ BMI of a particular school, then there is no need to have the religion column/attribute for the students, so we prefer to delete the column. Let us now see the syntax of deleting a column from a dataframe.
Syntax: 
 

del df['column_name']

Let us now see few examples:
Example 1: 
 

Python3




# importing the module
import pandas as pd
 
# creating a DataFrame
my_df = {'Name': ['Rutuja', 'Anuja'],
         'ID': [1, 2], 'Age': [20, 19]}
df = pd.DataFrame(my_df)
display("Original DataFrame")
display(df)
 
# deleting a column
del df['Age']
 
display("DataFrame after deletion")
display(df)


Output : 
 

Note the column ‘Age” has been dropped.
Example 2: 
 

Python3




# importing the module
import pandas as pd
 
# creating a DataFrame
my_df = {'Students': ['A', 'B', 'C', 'D'],
         'BMI': [22.7, 18.0, 21.4, 24.1],
         'Religion': ['Hindu', 'Islam',
                      'Christian', 'Sikh']}
df = pd.DataFrame(my_df)
display("Original DataFrame")
display(df)
 
# deleting a column
del df['Religion']
 
display("DataFrame after deletion")
display(df)


Output : 
 

Note that the unnecessary column, ‘Religion’ has been deleted successfully.
 

RELATED ARTICLES

Most Popular

Dominic
32324 POSTS0 COMMENTS
Milvus
84 POSTS0 COMMENTS
Nango Kala
6695 POSTS0 COMMENTS
Nicole Veronica
11860 POSTS0 COMMENTS
Nokonwaba Nkukhwana
11918 POSTS0 COMMENTS
Shaida Kate Naidoo
6807 POSTS0 COMMENTS
Ted Musemwa
7073 POSTS0 COMMENTS
Thapelo Manthata
6763 POSTS0 COMMENTS
Umr Jansen
6771 POSTS0 COMMENTS