pandas 重新采样FutureWarning [英] Pandas resample FutureWarning

查看:57
本文介绍了 pandas 重新采样FutureWarning的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个1分钟的酒吧OHLC价格CSV文件,我正尝试将其重新采样到15分钟的酒吧.我正在使用的代码来自以下链接,如下:

I have a 1-Minute bar OHLC price CSV file that I am trying to resample to 15-Minute bars. The code that I am using is from this link, and is follows:

ohlc_dict = {'open':'first', 'high':'max', 'low':'min', 'close': 'last'}

price15m = df.resample('15Min', how=ohlc_dict, closed='right').dropna(how='any')

我正在获得预期的重采样数据帧,但此警告也是如此:

I am getting the expected resample dataframe, but this warning too:

FutureWarning: how in .resample() is deprecated
the new syntax is .resample(...)..apply(<func>)
  ohlc_dict = {'open':'first', 'high':'max', 'low':'min', 'close': 'last'}

建议使用此语法,但我不确定如何:

The suggestion is to use this syntax but I am not sure how to:

the new syntax is .resample(...)..apply(<func>)

有人可以指出我正确的方向吗?非常感谢!

Can someone point me in the right direction? Thanks very much!

推荐答案

您可以使用

You can use Resampler.agg:

price15m = df.resample('15Min', closed='right').agg(ohlc_dict).dropna(how='any')

这篇关于 pandas 重新采样FutureWarning的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆