次のエラー メッセージが表示されるのはなぜですか? 重複列に関数を適用しようとしています。解決策は次のようなことだとは言わないでくださいdf["a"] = 2 * df["a"]
。これは、私が現在取り組んでいる、より複雑なものの単純化された例です。
>>> df = pd.DataFrame({"a" : [0,1,2], "b" : [1,2,3]})
>>> df[["a", "a"]].apply(lambda x: x[0] + x[1], axis = 1)
Traceback (most recent call last):
File "C:\Users\Alexander\Anaconda3\lib\site-packages\pandas\indexes\base.py", line 1980, in get_value
tz=getattr(series.dtype, 'tz', None))
File "pandas\index.pyx", line 103, in pandas.index.IndexEngine.get_value (pandas\index.c:3332)
File "pandas\index.pyx", line 111, in pandas.index.IndexEngine.get_value (pandas\index.c:3035)
File "pandas\index.pyx", line 154, in pandas.index.IndexEngine.get_loc (pandas\index.c:3955)
File "pandas\index.pyx", line 169, in pandas.index.IndexEngine._get_loc_duplicates (pandas\index.c:4236)
TypeError: unorderable types: str() > int()
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\Users\Alexander\Anaconda3\lib\site-packages\pandas\core\frame.py", line 4061, in apply
return self._apply_standard(f, axis, reduce=reduce)
File "C:\Users\Alexander\Anaconda3\lib\site-packages\pandas\core\frame.py", line 4157, in _apply_standard
results[i] = func(v)
File "<stdin>", line 1, in <lambda>
File "C:\Users\Alexander\Anaconda3\lib\site-packages\pandas\core\series.py", line 583, in __getitem__
result = self.index.get_value(self, key)
File "C:\Users\Alexander\Anaconda3\lib\site-packages\pandas\indexes\base.py", line 2000, in get_value
raise IndexError(key)
IndexError: (0, 'occurred at index 0')