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.
import pandas as pd import numpy as np df = pd.DataFrame() df['Name'] = ['John', 'Doe', 'Bill'] df['Promoted'] = [True, False,True] df['Marks'] = [82, 38, 63] df
Name Promoted Marks 0 John True 82 1 Doe False 38 2 Bill True 63

Drop column "Promoted"

df = df.drop('Promoted', 1) df
Name Marks 0 John 82 1 Doe 38 2 Bill 63
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:
df.drop('column_name', axis=1, inplace=True)
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.
df = df.drop(df.columns[[0, 2]], axis=1)
Promoted 0 True 1 False 2 True

How to drop one or multiple columns from Dataframe

errors='ignore'

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.
df = df.drop('NotExist', axis=1)
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.
df = df.drop('NotExist', axis=1,errors='ignore')