我有一个数据框“资产”,列包括“方向”、“打开”、“关闭”和“摆动”。我想生成一个列“Break”,因此:
if (((asset['Direction'] == 1) & (asset.open.shift(2) <= asset['Swing']) & (asset.close.shift(2) >= asset['Swing']) & (asset.open.shift(1) >= asset['Swing']) & (asset.close.shift(1) >= asset['Swing']) & (asset.open >= asset['Swing']) & (asset.close >= asset['Swing'])) | ((asset['Direction'] == -1) & (asset.open.shift(2) >= asset['Swing']) & (asset.close.shift(2) <= asset['Swing']) & (asset.open.shift(1) <= asset['Swing']) & (asset.close.shift(1) <= asset['Swing']) & (asset.open <= asset['Swing']) & (asset.close <= asset['Swing']))): asset['Break'] = True
但是,这会产生以下错误:
"The truth value of a {type(self).__name__} is ambiguous. Use a.empty, a.bool(), a.item(), a.any() or a.all()."
我以为我使用了正确的“按位”运算符来避免这种情况,但错误仍然存在......
梵蒂冈之花
相关分类