gpt4 book ai didi

Python/ Pandas -ValueError : Incompatible indexer with Series

转载 作者:行者123 更新时间:2023-11-28 21:41:25 33 4
gpt4 key购买 nike

我有一个数据框:

df:

A B
id
3 'Yes' 23
5 'Yes' 67
6 'No' 56
8 'No' 23

我有另一个数据框:

calc:
A B
id
3 'No' 4

我想用计算值更新 df。我正在尝试使用以下内容:

tgsm.loc[i]=calc

但是,这是行不通的。我不断收到以下错误:

File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/pandas/core/indexing.py", line 693, in _align_series
raise ValueError('Incompatible indexer with Series')
ValueError: Incompatible indexer with Series

如果尝试 tgsm.loc[i]=calc[i],它会让我遇到另一个错误:

File "pandas/index.pyx", line 137, in pandas.index.IndexEngine.get_loc (pandas/index.c:4154)
File "pandas/index.pyx", line 159, in pandas.index.IndexEngine.get_loc (pandas/index.c:4018)
File "pandas/hashtable.pyx", line 675, in pandas.hashtable.PyObjectHashTable.get_item (pandas/hashtable.c:12368)
File "pandas/hashtable.pyx", line 683, in pandas.hashtable.PyObjectHashTable.get_item (pandas/hashtable.c:12322)
KeyError: 3

谁能帮助启发我的旅程?

最佳答案

您可以使用 update方法直接覆盖它。

df.update(calc)

关于Python/ Pandas -ValueError : Incompatible indexer with Series,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44792362/

33 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com