我有一个很老的脚本,它的工作原理非常好,它被设计成使用熊猫.resample和.agg获取滴答(出价和询问)数据,并将其转化为OHLC数据,如下所示:
df = pd.DataFrame(list(MDB.CHART.find()))
DF = df[['dt','bid','ask']]
DF = DF.set_index('dt')
DB = DF['bid'].resample('2T').agg({ 'openbid' : 'first',
'highbid' : 'max',
'lowbid' : 'min',
'closebid': 'last'})
DA = DF['ask'].resample('2T').agg({ 'openask' : 'first',
'highask' : 'max',
'lowask' : 'min',
'closeask': 'last'})
dg = pd.concat([DB, DA], axis = 1)
And it would produce the following DataFrame layout:
dt openbid highbid lowbid closebid openask highask lowask closeask
....
....但是,现在当我运行相同的脚本(使用完全相同的数据)时,我得到了以下内容:
bid ask
dt
closeask 2015-08-19 06:00:00 NaN 1.10619
2015-08-19 06:02:00 NaN 1.10636
2015-08-19 06:04:00 NaN 1.10646
2015-08-19 06:06:00 NaN 1.10657
2015-08-19 06:08:00 NaN 1.10649
... ... ...
openbid 2015-08-20 13:28:00 1.11661 NaN
2015-08-20 13:30:00 1.11683 NaN
2015-08-20 13:32:00 1.11684 NaN
2015-08-20 13:34:00 1.11697 NaN
2015-08-20 13:36:00 1.11673 NaN
[7592 rows x 2 columns]我认为,还是假设熊猫已经(再次)改变了resample和agg的功能?有人能拿出他们的魔杖,帮我省去把头放在医生旁边的麻烦吗?
谢谢。
ps。当我使用以下内容时
df = (DF.resample('2T').agg({'Open': 'first', 'High': 'max', 'Low': 'min', 'Close': 'last'}))
I am getting a future warning:
FutureWarning: using a dict with renaming is deprecated and will be removed in a future version但到目前为止,医生里什么都没有!
发布于 2017-11-24 18:07:09
因此,从现在开始,在使用出价和询问数据时,我们必须使用以下方法,因为用dict重命名很快就会贬值:
db = DF.bid.resample('2T').ohlc().add_suffix('bid')
da = DF.ask.resample('2T').ohlc().add_suffix('ask')
df = pd.concat([db, da], axis = 1)
df.head(3)
openbid highbid lowbid closebid openask highask lowask closeask
dt
2015-08-19 06:00:00 1.10586 1.10620 1.10558 1.10615 1.10587 1.10623 1.10560 1.10619
2015-08-19 06:02:00 1.10615 1.10650 1.10611 1.10634 1.10618 1.10652 1.10614 1.10636
2015-08-19 06:04:00 1.10634 1.10674 1.10623 1.10645 1.10637 1.10676 1.10624 1.10646https://stackoverflow.com/questions/47477789
复制相似问题