我知道这个错误消息之前已经在这里讨论过,但我仍然不知道如何让它工作。我正在尝试使用多个条件执行 np.where 语句。下面是我的代码。我收到错误消息“关键字不能是表达式”,它突出显示了“聚合['Counter'] > 1”之后的空格。
aggregate['1'] = np.where(np.logical_and(aggregate['Counter'] > 1, aggregate['2'].shift(1) = aggregate['3']), 0, aggregate['2'])
最佳答案
比较运算符是==
,不是=
:
...aggregate['2'].shift(1) == aggregate['3']),...
^^ here
关于 python - "Keyword cannot be an expression",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35205558/