如何使用numpy的“ where”功能?

时间:2019-07-25 09:21:16

标签: python-3.x pandas numpy syntax-error

我有一个pandas数据框,并且我使用numpy函数比较两列,并根据该条件添加另一列,但是每次遇到语法错误时,我都会这样做。

signals = pd.DataFrame(index=df.index)
signals = df
signals['signal'] = 0.0
signals['signal'] = np.where((signals['close'] >= signals['upper'] & (signals['something'] >= 30) , -1, 0)
signals['signal'] = np.where((signals['close'] <= signals['lower'] & (signals['somthing'] >= 30) ,  1, 0)
File "<ipython-input-48-0eda6e639e76>", line 5
    signals['signal'] = np.where((signals['close'] <= signals['lower'] & (signals['something'] >= 30) ,  1, 0)
          ^
SyntaxError: invalid syntax

0 个答案:

没有答案