基于条件的数据框架值更改,即使打印它确实不起作用
我有一个带日期,时间和流量的数据框。我可以打印它的选择,并且可以正确捕获相应的数据,但是当我尝试更改值时,它无能为力。
下面的打印语句正确选择了相应的数据。
df["Flow"][ df["Date"] == "2022-02-23" ]
下面的重新分配无济于事。
df["Flow"][ df["Date"] == "2022-02-23" ] = 100
但是,如果我如下所示,将选择取出,则可以正确更改该值。
df["Flow"] = 100
我想添加更多条件,但是在其他条件的所有组合中,印刷品总是有效的,并且重新分配却没有。我缺少基本的东西吗?
I have a DataFrame with Date, Time, Flow. I can print selections of it and it grabs the corresponding data correctly, but when I try to change the values, it does nothing.
The print statement below selects the corresponding data correctly.
df["Flow"][ df["Date"] == "2022-02-23" ]
The reassignment below does nothing.
df["Flow"][ df["Date"] == "2022-02-23" ] = 100
But if I take the selection out as seen below, it correctly changes the value.
df["Flow"] = 100
I'd like to add more conditions, but in all combinations of the other conditions, the print always works and the reassignment doesn't. Is there something basic I'm missing?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
尝试这样的东西,看看它是否有效:
Try something like this and see if it works:
您可以使用列表理解:
df [“ flow”] = [100如果date ==“ 2022-02-23” else df [“ flow”] [i],i,enumerate(df [date'date'date'])]
You could use a list comprehension:
df["Flow"] = [100 if date == "2022-02-23" else df["Flow"][i] for i, date in enumerate(df["Date"])]