df = pd.read_csv('data/eurusd_dukascopy.csv')df.columns = ['timestamp', 'open', 'high', 'low', 'close', 'volume']df['oc'] = df.close - df.opendf['uptail'] = df['oc'].apply(lambda x: (df.high - df.close) if x >= 0 else (df.high - df.open))給出錯誤:ValueError:錯誤的項目數(shù)通過 2963,放置意味著 1我只想執(zhí)行以下操作:如果df.oc是正數(shù),則df.uptail = (df.high - df.close) ...else df.uptail = (df.high - df.open)我怎樣才能解決這個問題?
2 回答

藍山帝景
TA貢獻1843條經(jīng)驗 獲得超7個贊
看起來您想要uptail的是,close - open如果這是正數(shù),high - open如果close - open是負數(shù)或 0。
您可以使用以下代碼實現(xiàn)這一點:
df['uptail'] = df.high - df.open
df.loc[df.close > df.open, 'uptail'] = \
df.loc[df.close > df.open, 'high'] - df.loc[df.close > df.open, 'close']
添加回答
舉報
0/150
提交
取消