I've got a code where I'm modifying cells like this: IBM["PNL"][2]=3
. It works, but it shows up a warning:
A value is trying to be set on a copy of a slice from a DataFrame
See the caveats in the documentation: http://pandas.pydata.org/pandas-docs/stable/indexing.html#indexing-view-versus-copy
From what I can read in the article, a proper way of modifying the value would had been IBM.loc[2,"PNL"]=3
. However, that doesn't work for me, and it fails with following error:
Traceback (most recent call last):
File "<ipython-input-25-10debbad977d>", line 1, in <module>
IBM_dataframe.loc[0,"PNL"]
File "C:\Users\menkaur\Anaconda2\lib\site-packages\pandas\core\indexing.py", line 1310, in __getitem__
return self._getitem_tuple(key)
File "C:\Users\menkaur\Anaconda2\lib\site-packages\pandas\core\indexing.py", line 796, in _getitem_tuple
return self._getitem_lowerdim(tup)
File "C:\Users\menkaur\Anaconda2\lib\site-packages\pandas\core\indexing.py", line 922, in _getitem_lowerdim
section = self._getitem_axis(key, axis=i)
File "C:\Users\menkaur\Anaconda2\lib\site-packages\pandas\core\indexing.py", line 1482, in _getitem_axis
self._has_valid_type(key, axis)
File "C:\Users\menkaur\Anaconda2\lib\site-packages\pandas\core\indexing.py", line 1409, in _has_valid_type
key = self._convert_scalar_indexer(key, axis)
File "C:\Users\menkaur\Anaconda2\lib\site-packages\pandas\core\indexing.py", line 196, in _convert_scalar_indexer
return ax._convert_scalar_indexer(key, kind=self.name)
File "C:\Users\menkaur\Anaconda2\lib\site-packages\pandas\tseries\base.py", line 591, in _convert_scalar_indexer
self._invalid_indexer('index', key)
File "C:\Users\menkaur\Anaconda2\lib\site-packages\pandas\indexes\base.py", line 1284, in _invalid_indexer
kind=type(key)))
TypeError: cannot do index indexing on <class 'pandas.tseries.index.DatetimeIndex'> with these indexers [2] of <type 'int'>
Now, I'm confused
What am I doing wrong?