Drop multiple columns in Pandas

  • Post category:Pandas

In this Pandas tutorial, you will learn how to drop multiple columns in Pandas. You can drop multiple columns of Pandas DataFrame with the following code.

# import Pandas library
import pandas as pd

# create a dataframe
var = pd.DataFrame({'A': [41, 42, 43, 44, 45], 'B': [46, 47, 48, 49, 50], 'C': [51, 52, 53, 54, 55]})

# drop A and C column
var.drop(['A', 'C'], axis=1, inplace=True)

# display the dataframe
print(var)

Output:

    B
0  46
1  47
2  48
3  49
4  50

Free resources to learn advanced skills: AiHints and CodeAllow