How to delete any column from Series in Ipython?



I have created a Data frame using pandas library of Python

In [54]: frame2
year state pop debt eastern
one 2000 Ohio 1.5 NaN True
two 2001 Ohio 1.7 -1.2 True
three 2002 Ohio 3.6 NaN True
four 2001 Nevada 2.4 -1.5 False
five 2002 Nevada 2.9 -1.7 False

I want to know how to delete any column from the data Frame in python .As in R we can delete any column by assigning it to NULL .What is the method in python .
For example I want to delete the eastern column.



Columns in Python can be dropped using dataframe.drop command. Look at the below syntax.

DataFrame.drop(labels, axis=0, level=None, inplace=False, errors='raise')

You can read more detail about this syntax here.



This command will drop column REF_NO from dataframe train. To delete multiple columns, you can follow any of the below mentioned methods:

  1. train=train.drop(['REF_NO','children'],1) # It will delete two columns REF_NO and children
  2. train=train.drop(train.columns[[0, 1 ]],1) # It will delete same columns but based on index number.

Hope this helps!