Python 将Dict附加到数据帧时,我得到;类型错误:';dict';对象不可调用";
我想将字典作为新行附加到现有数据帧。Dict中的键与DataFrame中的列相同。代码示例:Python 将Dict附加到数据帧时,我得到;类型错误:';dict';对象不可调用";,python,pandas,dictionary,append,Python,Pandas,Dictionary,Append,我想将字典作为新行附加到现有数据帧。Dict中的键与DataFrame中的列相同。代码示例: in: df = pd.DataFrame([list(range(3))], columns=['Col {}'.format(x) for x in range(3)]) out: Col 0 Col 1 Col 2 0 0 1 2 现在我设置了我的dict:new_row={'Col 0':1,'Col 1':1,'Col 2':1} 但
in: df = pd.DataFrame([list(range(3))], columns=['Col {}'.format(x) for x in range(3)])
out:
Col 0 Col 1 Col 2
0 0 1 2
现在我设置了我的dict:new_row={'Col 0':1,'Col 1':1,'Col 2':1}
但是,如和示例2中所示,追加会引发错误:
in: df = df.append(new_row, ignore_index=True)
out: TypeError: 'dict' object is not callable
我错过了什么?谢谢 它在我的环境中运行得很好,您在添加之前是否更改了变量,如
df
?您以前可能编写了类似df.append=new_row
;删除并重新启动内核可能会奏效谢谢@mustafa和Jiang,重新启动内核就完成了。而df.append=new_row正是我以前做过的。非常感谢。