You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Apply to a DataFrame using lambda with a index/key (although that is in the DataFrame's index throws an error (a KeyError or IndexError respectively), perhaps it should exit more gracefully?
In [1]: x = pd.DataFrame(index=["a"])
In [2]: x
Out[2]:
Empty DataFrame
Columns: array([], dtype=object)
Index: array([a], dtype=object)
In [3]: x.apply(lambda x: x["a"], axis=1)
KeyError Traceback (most recent call last)
<ipython-input-3-80540f6c1d18> in <module>()
----> 1 x.apply(lambda x: x["a"], axis=1)
/Library/Python/2.7/site-packages/pandas-0.9.0-py2.7-macosx-10.7-intel.egg/pandas/core/frame.pyc in apply(self, func, axis, broadcast, raw, args, **kwds)
3750 if not broadcast:
3751 if not all(self.shape):
-> 3752 is_reduction = not isinstance(f(_EMPTY_SERIES),
3753 np.ndarray)
3754 if is_reduction:
<ipython-input-447-80540f6c1d18> in <lambda>(x)
----> 1 x.apply(lambda x: x["a"], axis=1)
/Library/Python/2.7/site-packages/pandas-0.9.0-py2.7-macosx-10.7-intel.egg/pandas/core/series.pyc in __getitem__(self, key)
462 def __getitem__(self, key):
463 try:
--> 464 return self.index.get_value(self, key)
465 except InvalidIndexError:
466 pass
/Library/Python/2.7/site-packages/pandas-0.9.0-py2.7-macosx-10.7-intel.egg/pandas/core/index.pyc in get_value(self, series, key)
689 raise InvalidIndexError(key)
690 else:
--> 691 raise e1
692 except Exception: # pragma: no cover
693 raise e1
KeyError: 'a'
I am trying to wrangle data from a huge number of Excel sheets (converting each sheet into a DataFrame but need to clean them before they are merged into something more sensible... I wanted to apply functions across these without worrying which are empty...
(same error in 0.9.1.)
The text was updated successfully, but these errors were encountered:
Apply to a DataFrame using lambda with a index/key (although that is in the DataFrame's index throws an error (a KeyError or IndexError respectively), perhaps it should exit more gracefully?
I am trying to wrangle data from a huge number of Excel sheets (converting each sheet into a DataFrame but need to clean them before they are merged into something more sensible... I wanted to apply functions across these without worrying which are empty...
(same error in 0.9.1.)
The text was updated successfully, but these errors were encountered: