【问题标题】:In pandas If we are re-sampling a 1-minute interval data to a 15-minute interval by averaging can we select how to re-sample and assiggn the data在 pandas 如果我们通过平均将 1 分钟间隔的数据重新采样到 15 分钟的间隔,我们可以选择如何重新采样和分配数据
【发布时间】:2020-05-02 05:43:53
【问题描述】:

示例:当我们有从早上 7 点到 8 点 1 分钟的数据时,如何将 7:00-7:15 1 分钟的数据分配给 7:15 的 15 分钟时间戳,以及如何做同样的事情从早上 7:00 到早上 7:15 的 1 分钟数据作为 15 分钟的平均值到早上 7:00 的时间戳

【问题讨论】:

    标签: python pandas timestamp


    【解决方案1】:

    如果我理解正确,你可以重新采样到你想要的 inverval,例如:

    In [16]: index = pd.date_range('2019-11-1', '2019-12-1', freq='1T')                                                                             
    
    In [17]: series = pd.Series(np.random.rand(len(index)), index=index)                                                                            
    
    In [18]: series = series.resample('15T').mean()  # Average over 15min intervals
    

    输出:

    In [19]: series.tail()                                                                                                                          
    Out[19]: 
    2019-11-30 23:00:00    0.392965
    2019-11-30 23:15:00    0.521111
    2019-11-30 23:30:00    0.563201
    2019-11-30 23:45:00    0.564622
    2019-12-01 00:00:00    0.762733
    Freq: 15T, dtype: float64
    

    【讨论】:

      【解决方案2】:

      (我无法评论,因此我添加了一个答案)您可以在 Felipe Lanza 的解决方案中添加窗口标签的位置,以定义“哪个 bin 边缘标签来标记存储桶”,右侧或左侧:

      series.resample('15min', label='right').mean()
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2021-12-10
        • 1970-01-01
        • 2021-12-02
        • 1970-01-01
        • 2022-01-09
        • 2021-11-18
        • 1970-01-01
        • 2019-01-13
        相关资源
        最近更新 更多