Pandas OHLC aggregation on OHLC data

前端 未结 5 1481
刺人心
刺人心 2020-12-22 23:57

I understand that OHLC re-sampling of time series data in Pandas, using one column of data, will work perfectly, for example on the following dataframe:

>         


        
5条回答
  •  一整个雨季
    2020-12-23 00:39

    This one seems to work,

    def ohlcVolume(x):
        if len(x):
            ohlc={ "open":x["open"][0],"high":max(x["high"]),"low":min(x["low"]),"close":x["close"][-1],"volume":sum(x["volume"])}
            return pd.Series(ohlc)
    
    daily=df.resample('1D').apply(ohlcVolume)
    

提交回复
热议问题