3.12. Deleting Columns#

import pandas as pd
import numpy as np
df=pd.DataFrame({
'Name':['Sahil','Sonia','Sourav','Vishal'],
'Age':[10,20,30,40],
'Gender':['M','F','M','M'],
'City':['J','K','L','P'],
'Work':[True,False,False,True]
}
)
df
Name Age Gender City Work
0 Sahil 10 M J True
1 Sonia 20 F K False
2 Sourav 30 M L False
3 Vishal 40 M P True

3.12.1. .drop() is used to delete cols#

3.12.2. Removing one column#

df.drop('Work',axis=1,inplace=True)
df
Name Age Gender City
0 Sahil 10 M J
1 Sonia 20 F K
2 Sourav 30 M L
3 Vishal 40 M P

3.12.3. Removing multiple columns#

cols=['Age','City']
df.drop(cols,axis=1,inplace=True)
df
Name Gender
0 Sahil M
1 Sonia F
2 Sourav M
3 Vishal M