# Import the library and create a dataframe object
import pandas
df = pandas.DataFrame({'A': [1, 2], 'B': [10, 20]})
# Delete column A del df['A']
# Print out the updated dataframe print(df)
B
0 10
1 20
The del command can be used to delete a pandas dataframe column.
Another alternative that would also delete a dataframe column is this:
df = df.drop('A', axis=1)
Note that drop does not modify the original dataframe. Instead, it returns a new modified dataframe object. In the line above, we are reassigning that new object to the existing df variable.
Practice what you just learned
Solve Python exercises and get instant AI feedback on your solutions.
Try ActiveSkill for Free →
Python Mega Course: Learn Python in 60 Days, Build 20 Apps
Learn Python on Udemy completely in 60 days or less by building 20 real-world applications from web development to data science.
