The pandas.DataFrame.drop() method in Pandas
The pandas.DataFrame.drop() function can used to drop the specified columns from the dataframe.
Syntax a) pandas.DataFrame.drop(labels=None, *, axis=0, index=None, columns=None, level=None, inplace=False, errors='raise')
b) pandas.DataFrame.drop(columns=None)
As the columns parameter is not the first parameter in the function, so when we are calling this function, it is required from us to specify the parameter name “columns” with the argument, otherwise, it will not work as expected.
Example: Let’s drop the column “Name” and “Salary” from the dataframe.
Python
mydata=pd.read_csv("employees.csv") data_transformed=mydata.drop(columns=["Name", "Salary"]) data_transformed
The output of the above code is shown below: