Pandas重新采样FutureWarning

4

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

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

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

我得到了期望的重采样数据框,但也出现了以下警告:
FutureWarning: how in .resample() is deprecated
the new syntax is .resample(...)..apply(<func>)
  ohlc_dict = {'open':'first', 'high':'max', 'low':'min', 'close': 'last'}

建议使用这个语法,但我不确定如何操作:
the new syntax is .resample(...)..apply(<func>)

有人能指导我正确的方向吗?非常感谢!

1个回答

5
您可以使用 Resampler.agg 方法:
price15m = df.resample('15Min', closed='right').agg(ohlc_dict).dropna(how='any')

谢谢!这很有道理。 - Tanmay

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接