示例:当我们有 7-8 am 1-minute 数据的数据时,如何将 7:00-7:15 1 分钟的数据分配给 7:15 的 15 分钟时间戳,以及如何从 7 开始执行相同操作: 00-7:15 am 1 分钟数据作为 15 分钟平均值到 7:00 am 时间戳
If I understood you right, you can just resample to the inverval you want, for example:
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
Output:
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
(我无法发表评论,因此我添加了一个答案)您可以在 Felipe Lanza 的解决方案中添加窗口标签的位置,以定义“用哪个 bin 边缘标签来标记桶”,向右或向左:
series.resample('15min', label='right').mean()
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.