Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/354.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python np.where:“;语法错误:关键字can';不要成为一种表达;_Python - Fatal编程技术网

Python np.where:“;语法错误:关键字can';不要成为一种表达;

Python np.where:“;语法错误:关键字can';不要成为一种表达;,python,Python,我试图结合以下逻辑 在A列中,其中B列=堆栈,然后A列*100,否则保持A列不变 df['Value'] = np.where(df['columnB'] = 'Stack', df['Value'] * 100) 为什么我会得到一个SyntaxError:keyword不能是一个表达式?您必须为二进制条件提供一个条件和两个结果 在不太了解您的情况下,dataframe我认为您应该做以下事情: df['Value'] = np.where(df['columnB'] == 'Stack', d

我试图结合以下逻辑

在A列中,其中B列=堆栈,然后A列*100,否则保持A列不变

df['Value'] = np.where(df['columnB'] = 'Stack', df['Value'] * 100)

为什么我会得到一个
SyntaxError:keyword不能是一个表达式?

您必须为二进制条件提供一个条件和两个结果

在不太了解您的情况下,
dataframe
我认为您应该做以下事情:

df['Value'] = np.where(df['columnB'] == 'Stack', df['columnA']*100, df['Value'])
这是因为在it国家:

numpy.where(condition[, x, y])
    Return elements chosen from x or y depending on condition.

Parameters: 
    condition : array_like, bool
    Where True, yield x, otherwise yield y.

因此,如果
columnB
'Stack'
,则
df['Value']
将填充
columnA
乘以100,否则,它将保留存储在
Value

的值。我看到一个错误
df['columnB']='Stack'
应该是
df['columnB']='Stack'
该死,我现在看到了。我的错误。。那么我应该删除这个吗?这取决于你是否认为其他人会遇到这个问题,并且可能会觉得这个有用。但这是相当琐碎的。