Python 语法错误:关键字can';t不是表达式(将行与表达式匹配)

Python 语法错误:关键字can';t不是表达式(将行与表达式匹配),python,machine-learning,optimization,Python,Machine Learning,Optimization,我有这个档案: 我不想计算有表达式“Hold centralized”的行数 我试过了 count(df.x="Hold centralized") 但我明白了: syntax error:keyword can't be an expression 如何计算与表达式匹配的行数 df[df["x"] == "Hold centralized"]["x"].count() df.x.isin([“Hold centralized”]).value_counts()首

我有这个档案:

我不想计算有表达式“Hold centralized”的行数

我试过了

      count(df.x="Hold centralized")
但我明白了:

      syntax error:keyword can't be an expression
如何计算与表达式匹配的行数

df[df["x"] == "Hold centralized"]["x"].count()

df.x.isin([“Hold centralized”]).value_counts()
首先,
=
用于赋值,而不是检查相等性,这是
=
其次,您似乎在混合python和Panda。如果可能的话,您应该为数据帧使用pandas或numpy方法