pydata/pandas — Issue #840: error during line-wise iteration over DataFrame
Author: bgbg
Created: 2012-02-29 09:37:06+00:00
State: open

In the code below I create a `DataFame` and iterate over its lines using `ix`

In [37]: a = pandas.DataFrame(rand(4, 2), columns = list('ab'))

In [38]: print a
a b
0 0.372630 0.680347
1 0.557162 0.815903
2 0.058282 0.371265
3 0.772931 0.925008

In [39]: for l in a.ix:
....: print l
....:
a 0.372630
b 0.680347
a 0.557162
b 0.815903
Name: 1
a 0.058282
b 0.371265
Name: 2
a 0.772931
b 0.925008
Name: 3
---------------------------------------------------------------------------
KeyError Traceback (most recent call last)
Q:\Groups\Bioinformatics\IgG assay optimization 2011\script development\scriptDevelopment\src\ in ()
----> 1 for l in a.ix:
2 print l
3

c:\python27\lib\site-packages\pandas\core\indexing.pyc in __getitem__(self, key)
30 return self._getitem_tuple(key)
31 else:
---> 32 return self._getitem_axis(key, axis=0)
33
34 def _get_label(self, label, axis=0):

c:\python27\lib\site-packages\pandas\core\indexing.pyc in _getitem_axis(self, key, axis)
182 idx = labels[key]
183
--> 184 return self._get_label(idx, axis=0)
185 else:
186 labels = self.obj._get_axis(axis)

c:\python27\lib\site-packages\pandas\core\indexing.pyc in _get_label(self, label, axis)
36 return self.obj.xs(label, axis=axis, copy=False)
37 except Exception:
---> 38 return self.obj.xs(label, axis=axis, copy=True)
39
40 def _slice(self, obj, axis=0):

c:\python27\lib\site-packages\pandas\core\frame.pyc in xs(self, key, axis, level, copy)
1592 loc, new_index = self.index.get_loc_level(key)
1593 else:
-> 1594 loc = self.index.get_loc(key)
1595
1596 if np.isscalar(loc):

c:\python27\lib\site-packages\pandas\core\index.pyc in get_loc(self, key)
493 loc : int
494 """
--> 495 return self._engine.get_loc(key)
496
497 def get_value(self, series, key):

c:\python27\lib\site-packages\pandas\_engines.pyd in pandas._engines.DictIndexEngine.get_loc (pandas\src\engines.c:2498)()

c:\python27\lib\site-packages\pandas\_engines.pyd in pandas._engines.DictIndexEngine.get_loc (pandas\src\engines.c:2460)()

KeyError: 4