How to drop one or multiple columns from Dataframe
Pandas DataFrame is a two-dimensional labeled data structure with columns of potentially different data-types. Pandas DataFrame drop() method remove rows or columns by specifying label names and corresponding axis (0 for rows and 1 for columns.), or by specifying directly index or column names.
Drop column "Promoted"
where 1 is the axis number (0 for rows and 1 for columns.)
In order to delete the column without having to reassign DataFrame you can do:
Please note that "inplace=True" was added in pandas v0.13 and it won't work on older versions.
Using Column Number
If you want to drop by column number instead of by column label, try this to drop columns.
errors='ignore' is the ability to drop columns only if they exist and it available from pandas 0.16.1 onward. This way you can cover more use cases, and when using errors='ignore' , it will only drop the existing columns from the labels passed to it.
When you run this code, you will get the message KeyError: "['NotExist'] not found in axis" . If you use the argument errors='ignore' then drop() method will only drop the existing columns from the labels passed to it.