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

问题描述

我有一个 1 分钟柱形 OHLC 价格 CSV 文件,我正在尝试将其重新采样为 15 分钟柱形.我使用的代码来自这个 link,如下:

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!

推荐答案

您可以使用 Resampler.agg:

You can use Resampler.agg:

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

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

08-31 04:32