如何解决ValueError:索引器与 DataFrame 不兼容
我试图根据另一个数据框中的一行覆盖一个数据框中的一行。对替代方法持开放态度!
这个循环运行了 15 次,然后出错。奇怪的。同一种循环在同一个函数中运行得很好。
for row in rows_unique:
print(row in df_a.index) # all True...
print(row in df_b.index) # all True...
df_a.loc[row] = df_b.loc[row]
这是跟踪的尾部
~/.pyenv/versions/3.8.7/envs/jupyterlab3/lib/python3.8/site-packages/pandas/core/indexing.py in __setitem__(self,key,value)
690
691 iloc = self if self.name == "iloc" else self.obj.iloc
--> 692 iloc._setitem_with_indexer(indexer,value,self.name)
693
694 def _validate_key(self,axis: int):
~/.pyenv/versions/3.8.7/envs/jupyterlab3/lib/python3.8/site-packages/pandas/core/indexing.py in _setitem_with_indexer(self,indexer,name)
1635 self._setitem_with_indexer_split_path(indexer,name)
1636 else:
-> 1637 self._setitem_single_block(indexer,name)
1638
1639 def _setitem_with_indexer_split_path(self,name: str):
~/.pyenv/versions/3.8.7/envs/jupyterlab3/lib/python3.8/site-packages/pandas/core/indexing.py in _setitem_single_block(self,name)
1852
1853 elif isinstance(value,ABCDataFrame) and name != "iloc":
-> 1854 value = self._align_frame(indexer,value)
1855
1856 # check for chained assignment
~/.pyenv/versions/3.8.7/envs/jupyterlab3/lib/python3.8/site-packages/pandas/core/indexing.py in _align_frame(self,df)
2080 return val
2081
-> 2082 raise ValueError("Incompatible indexer with DataFrame")
2083
2084
ValueError: Incompatible indexer with DataFrame
Trace 非常注重 iloc。
熊猫 v1.2.3
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。