Informatics Practices
How would you delete columns from a dataframe ?
Python Pandas
5 Likes
Answer
To delete columns from a dataframe, we use the del statement with the syntax:
del <Df object>[<column name>]
OR
df.drop([<column name], axis = 1).
For example, the statement to delete columns A, B from a dataframe df is del df['A'] and del df['B'] or df.drop(['A', 'B'], axis = 1).
Answered By
2 Likes