简体   繁体   English

使用 df.loc 为 dataframe 单元分配新值

[英]Assigning a new value to a dataframe cell using df.loc

Can someone please tell me what the right syntax would be to do the following:有人可以告诉我执行以下操作的正确语法是什么:

dfpollution3.loc(max(dfpollution3.index),'newhospinextday') = 10

I get the following error:我收到以下错误:

    dfpollution3.loc(max(dfpollution3.index),'newhospinextday') = 10
    ^
SyntaxError: cannot assign to function call

This is an illegal operation that you are trying to use, refer to the link below SyntaxError: "can't assign to function call"这是您尝试使用的非法操作,请参阅下面的链接SyntaxError: "can't assignment to function call"

The issue is that you are using the incorrect brackets, and you should use at not loc in this case.问题是您使用了不正确的括号,在这种情况下您应该使用at not loc

dfpollution3.at[max(dfpollution3.index),'newhospinextday'] = 10

Indexing is done with square brackets [], and function calls are with parentheses ().索引使用方括号 [] 完成,function 调用使用括号 ()。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM