Closed
Description
related is #6076 (loc
not working either)
It would be nice if common operations like indexing/slicing is available for sparse dataframes as for their dense counterparts.
Thanks!
In [1]: import pandas as pd
In [2]: import numpy as np
In [3]: A = np.zeros((3,4))
In [4]: A[:] = np.nan
In [5]: A[2,3] = 1
In [6]:
In [6]: Y = pd.DataFrame(A)
In [7]: print Y.iloc[2,3] # print 1.0
1.0
In [8]: sY = Y.to_sparse()
In [9]: print sY.iloc[2,3]
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
<ipython-input-9-0674f68ef869> in <module>()
----> 1 print sY.iloc[2,3]
/usr/local/Cellar/python/2.7.5/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pandas/core/indexing.pyc in __getitem__(self, key)
667 def __getitem__(self, key):
668 if type(key) is tuple:
--> 669 return self._getitem_tuple(key)
670 else:
671 return self._getitem_axis(key, axis=0)
/usr/local/Cellar/python/2.7.5/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pandas/core/indexing.pyc in _getitem_tuple(self, tup)
774 continue
775
--> 776 retval = getattr(retval,self.name)._getitem_axis(key, axis=i)
777
778 return retval
/usr/local/Cellar/python/2.7.5/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pandas/core/indexing.pyc in _getitem_axis(self, key, axis)
803 raise ValueError("Cannot index by location index with a non-integer key")
804
--> 805 return self._get_loc(key,axis=axis)
806
807 def _convert_to_indexer(self, obj, axis=0):
/usr/local/Cellar/python/2.7.5/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pandas/core/indexing.pyc in _get_loc(self, key, axis)
61
62 def _get_loc(self, key, axis=0):
---> 63 return self.obj._ixs(key, axis=axis)
64
65 def _slice(self, obj, axis=0, raise_on_error=False):
/usr/local/Cellar/python/2.7.5/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pandas/core/frame.pyc in _ixs(self, i, axis, copy)
1880 new_values = self._data.fast_2d_xs(i, copy=copy)
1881 except:
-> 1882 new_values = self._data.fast_2d_xs(i, copy=True)
1883 return Series(new_values, index=self.columns,
1884 name=self.index[i])
AttributeError: '_SparseMockBlockManager' object has no attribute 'fast_2d_xs'