How to drop values from the column of a Data frame?

ipython

#1

I have created a data frame in Ipython notebook and I have used the drop function to drop the rows but when I have tried to drop the columns ,it shows the error.

 data = DataFrame(np.arange(16).reshape((4, 4)),
....: index=['Ohio', 'Colorado', 'Utah', 'New York'],
....: columns=['one', 'two', 'three', 'four'])
 data.drop(['Colorado', 'Ohio'])
                one     two     three      four
Utah          8          9        10        11
New York      12         13        14        15

trying to drop rows.

data.drop('two')

ValueError                                Traceback (most recent call last)
<ipython-input-12-748a26662125> in <module>()
----> 1 data.drop('two')

C:\Users\hp pc\Anaconda\lib\site-packages\pandas\core\generic.pyc in drop(self, labels, axis, level, inplace, errors)
   1595                 new_axis = axis.drop(labels, level=level, errors=errors)
   1596             else:
-> 1597                 new_axis = axis.drop(labels, errors=errors)
   1598             dropped = self.reindex(**{axis_name: new_axis})
   1599             try:

C:\Users\hp pc\Anaconda\lib\site-packages\pandas\core\index.pyc in drop(self, labels, errors)
   2568         if mask.any():
   2569             if errors != 'ignore':
-> 2570                 raise ValueError('labels %s not contained in axis' % labels[mask])
   2571             indexer = indexer[~mask]
   2572         return self.delete(indexer)

ValueError: labels ['two'] not contained in axis

How to remove this error.


#2

@sid100158- for dropping the element column wise you have specified the axis because the default axis is 0 and if we will not specify axis it will try to drop the element row wise and while doing it will not find the given argument .Therefore, it will give an error.

data.drop('two', axis=1)

          one   three   four 
Ohio       0     2        3 
Colorado   4     6        7 
Utah       8     10      11 
New York   12    14      15

Hope this helps!

Regards,
Hinduja