首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >熊猫协约与OHLC发行

熊猫协约与OHLC发行
EN

Stack Overflow用户
提问于 2017-11-24 17:24:30
回答 1查看 285关注 0票数 0

我有一个很老的脚本,它的工作原理非常好,它被设计成使用熊猫.resample.agg获取滴答(出价和询问)数据,并将其转化为OHLC数据,如下所示:

代码语言:javascript
复制
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
....
....

但是,现在当我运行相同的脚本(使用完全相同的数据)时,我得到了以下内容:

代码语言:javascript
复制
                                  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]

我认为,还是假设熊猫已经(再次)改变了resampleagg的功能?有人能拿出他们的魔杖,帮我省去把头放在医生旁边的麻烦吗?

谢谢。

ps。当我使用以下内容时

代码语言:javascript
复制
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

但到目前为止,医生里什么都没有!

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2017-11-24 18:07:09

因此,从现在开始,在使用出价和询问数据时,我们必须使用以下方法,因为用dict重命名很快就会贬值:

代码语言:javascript
复制
    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.10646
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/47477789

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档