Pandas 重新采样 FutureWarning

Tan*_*may 4 python apply pandas

我有一个 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')
Run Code Online (Sandbox Code Playgroud)

我收到了预期的重新采样数据帧,但也出现了此警告:

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

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

the new syntax is .resample(...)..apply(<func>)
Run Code Online (Sandbox Code Playgroud)

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

jez*_*ael 5

您可以使用Resampler.agg:

price15m = df.resample('15Min', closed='right').agg(ohlc_dict).dropna(how='any')
Run Code Online (Sandbox Code Playgroud)