python - "Keyword cannot be an expression"

标签 python numpy pandas

我知道这个错误消息之前已经在这里讨论过,但我仍然不知道如何让它工作。我正在尝试使用多个条件执行 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/

相关文章:

python - 使用 `contains` 合并 DataFrame(不是完全匹配!)

python - 检查一对值是否在 Pandas 的一对列中

python - 先前工作配置的 django-pyodbc-azure 回滚错误 - 第 389 行

python - 取消列出数据框 pandas 中的字典列表

python - 使用 numpy 对两个相同大小的矩阵进行卷积

python - 使用 tsfresh 中的 extract_(relevant_)features 时出现(类型转换)错误

python - 在 Dataframe : labels not contained in axis 中删除行

python - Pandas 将文本文件读入数据框

python - gensim Word2vec 作为 HTTP 服务的代码 'KeyedVectors' 属性错误

python - 评估在命令行上传递的公式