无法分配值,因为试图在DataFrame的切片副本上设置“值”

我有一个名为app.run(debug=True) 的数据框,其中有一个名为histPrice的列和一个名为“ test”的子索引列,我将其设置为5。

Allocation %

我想将第一个索引[Input]: histPrice['Allocation %',"test"] = 5 [Output]: print(histPrice['Allocation %']) Date test 2019-11-04 5 2019-11-01 5 2019-10-31 5 2019-10-30 5 2019-10-29 5 2019-10-28 5 ... 的值替换为值10。我尝试了以下逻辑:

2019-11-04

运行代码后,我什么都没有更新,我仍然在第一行中看到5,而不是出现以下警告的10:

histPrice['Allocation %'].loc[histPrice['Allocation %'].index[0],'test'] = 10

我认为这是因为原始副本没有被覆盖。如何重新编写逻辑,以便正确替换值?

tuyongqang 回答:无法分配值,因为试图在DataFrame的切片副本上设置“值”

暂时没有好的解决方案,如果你有好的解决方案,请发邮件至:iooj@foxmail.com
本文链接:https://www.f2er.com/3161992.html

大家都在问