代码之家  ›  专栏  ›  技术社区  ›  Tanmay

熊猫重新取样未来警告

  •  4
  • Tanmay  · 技术社区  · 7 年前

    我有一个1分钟的酒吧OHLC价格CSV文件,我正试图重新采样到15分钟酒吧。我使用的代码来自 link ,如下所示:

    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 回复  |  直到 7 年前
        1
  •  4
  •   jezrael    7 年前

    您可以使用 Resampler.agg :

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