我有股票时间序列,我正在尝试根据最近的交易更新日期的高点。例如,如果最后交易高于已知高点,则将当天的高点更新为最后一笔交易等。
我试图实现解决方案here并阅读其他一些解决方案来使用IF函数原始更新raw但我在运行此代码后失败并收到错误:
df = pd.read_csv('C:/2017-11-20.csv')
df.set_index('dateTime', inplace=True)
df['high'] = 0
high = 0
for dateTime, row in enumerate(df.iterrows()):
if df['tradePrice'] > df['high']:
df['high'] = df['tradePrice']
else:
df['high'] = df['high']
错误是:
ValueError:系列的真值是不明确的。使用a.empty, a.bool(),a.item(),a.any()或a.all()。
数据(前5行)是:
SecurityID,日期时间,ASK1,ask1Volume,标段,bid1Volume,ASK2,ask2Volume,标段2,bid2Volume,ask3,ask3Volume,标段3,bid3Volume,tradePrice,tradeVolume,isTrade 2318276,2017-11-20 08:00:09.052240,12869.0,1,12868.0,3,12870.0,19,12867.5,2,12872.5,2,12867.0,1,0.0,0,0 2318276,2017-11-20 08:00:09.052260,12869.0,1,12868.0,3,12870.0,19,12867.5,2,12872.5,2,12867.0,1,12868.0,1,1 2318276,2017-11-20 08:00:09.052260,12869.0,1,12868.0,2,12870.0,19,12867.5,2,12872.5,2,12867.0,1,12868.0,1,0 2318276,2017-11-20 08:00:09.052270,12869.0,1,12868.0,2,12870.0,19,12867.5,2,12872.5,2,12867.0,1,12868.0,1,1 2318276,2017-11-20 08:00:09.052270,12869.0,1,12868.0,1,12870.0,19,12867.5,2,12872.5,2,12867.0,1,12868.0,1,0
答案 0 :(得分:0)
df['high'] = df.tradePrice.rolling(window=df.__len__(),min_periods=1,center=False).max()