我有一个数据帧:
df:
A B
id
3 'Yes' 23
5 'Yes' 67
6 'No' 56
8 'No' 23
Run Code Online (Sandbox Code Playgroud)
我有另一个数据帧:
calc:
A B
id
3 'No' 4
Run Code Online (Sandbox Code Playgroud)
我想用calc值更新df.我正在尝试使用以下内容:
tgsm.loc[i]=calc
Run Code Online (Sandbox Code Playgroud)
但是,这不起作用.我一直收到以下错误:
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
Run Code Online (Sandbox Code Playgroud)
如果尝试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
Run Code Online (Sandbox Code Playgroud)
任何人都可以帮助启发我的旅程吗?
| 归档时间: |
|
| 查看次数: |
3166 次 |
| 最近记录: |