1
以下是我的數據集填充,它是通用數據集的一個布爾子集x。在數據子集上使用df.iterrows()
fills = x.loc[(x['price'] == min_bid) & (x['bid?'] == 'T') & (x['type'] == 'trade')]
fills
time price bid? type id quantity
2509 2017-01-03 16:00:38.185 38.25 T trade 2422 400.0
2514 2017-01-03 16:00:59.849 38.25 T trade 2422 400.0
2623 2017-01-03 16:05:08.626 38.25 T trade 2422 200.0
2624 2017-01-03 16:05:09.295 38.25 T trade 2422 600.0
2749 2017-01-03 16:10:25.262 38.25 T trade 2422 100.0
2922 2017-01-03 16:18:56.218 38.25 T trade 2422 1500.0
2947 2017-01-03 16:20:08.441 38.25 T trade 2422 200.0
2953 2017-01-03 16:20:38.836 38.25 T trade 2422 400.0
2995 2017-01-03 16:25:06.441 38.25 T trade 2422 200.0
2997 2017-01-03 16:25:07.438 38.25 T trade 2422 1100.0
3053 2017-01-03 16:29:47.373 38.25 T trade 2422 600.0
3064 2017-01-03 16:29:54.444 38.25 T trade 4844 4700.0
3066 2017-01-03 16:29:54.700 38.25 T trade 2422 100.0
通過索引我想在這裏實現的是循環罷了,併爲每一行我想從X獲得一些值添加到兩個運行總計之一。
quantity_cleared = 0
quantity_remaining = 0
for index, rows in fills.iterrows():
offer_size = x['quantity'][(x['price'] == min_bid + tick_size) & (x['bid?'] == 'F') & (x['type'] == 'quote')].loc[:row].iloc[-1]
trades_done = x['quantity'][(x['price'] == min_bid + tick_size) & (x['bid?'] == 'F') & (x['type'] == 'trade')].loc[row:].sum()
if trades_done >= offer_size:
quantity_cleared += fills['quantity']['row']
else:
quantity_remaining += fills['quantity']['row']
我的代碼返回錯誤:
SystemError: <class 'TypeError'> returned a result with an error set
任何意見,將不勝感激。謝謝!
你可以提供一個自包含的例子證明了什麼問題? – BrenBarn