In this Pandas tutorial, you will learn how to drop a column in Pandas DataFrame. You can easily drop a column with the following code.
# import Pandas library import pandas as pd # create a dataframe var = pd.DataFrame({'A': [21, 22, 23, 24, 25], 'B': [26, 27, 28, 29, 30], 'C': [51, 62, 63, 64, 55]}) # drop a column in Pandas var.drop('A', axis=1, inplace=True) # display the dataframe print(var)
Output:
B C 0 26 51 1 27 62 2 28 63 3 29 64 4 30 55
Free resources to learn advanced skills: AiHints and CodeAllow