How to drop columns in a pandas dataframe ? 0 0

Last updated on Oct 28, 2020 08:18 AM in Academics Team
Posted ByDataTrained

The drop function removes the columns from the data without affecting the rest of the features.

data.drop(['column_name'], axis=1, inplace=True)

The axis parameter present inside the function can take the below values:
1. axis=0 is set to remove the index (rows).
2. axis=1 is set to remove the columns.

We have set the axis parameter to remove the columns we don't want, i. e. axis=1

The inplace determines the changes in the data.
1. If inplace=True, the column data will drop features passed in the function permanently from the data.
2. When inplace=False, the column data will drop features, However, no permanent change will appear.

 

In order to drop multiple columns, You can refer to the below syntax.

data.drop(['column_name1','column_name2','column_name3'], axis=1, inplace=True/False)

** The time is base on America/New_York timezone