在特定的开始时间对每小时的TimeSeries重新采样 [英] Resample hourly TimeSeries with certain starting hour

查看:61
本文介绍了在特定的开始时间对每小时的TimeSeries重新采样的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想每天从某个小时开始(每天24小时)对TimeSeries进行重新采样.

I want to resample a TimeSeries in daily (exactly 24 hours) frequence starting at a certain hour.

赞:

index = date_range(datetime(2012,1,1,17), freq='H', periods=60)

ts = Series(data=[1]*60, index=index)

ts.resample(rule='D', how='sum', closed='left', label='left')

我得到的结果:

2012-01-01  7
2012-01-02 24
2012-01-03 24
2012-01-04  5
Freq: D

我希望得到的结果:

2012-01-01 17:00:00 24
2012-01-02 17:00:00 24
2012-01-03 17:00:00 12
Freq: D

几周前,您可以将'24H'传递给freq参数,它工作得很好. 但是现在它将'24H'组合为'1D'.

Some weeks ago you could pass '24H' to the freq argument and it worked totally fine. But now it combines '24H' to '1D'.

我是否使用了现在已修复的带有'24H'的错误? 而且我如何才能以一种高效且蟒蛇(或大熊猫)的方式获得理想的结果呢?

Was I using a bug with '24H' which is fixed now? And how can i get the wished result in a efficient and pythonic (or pandas) way back?

版本:

  • python 2.7.3
  • pandas 0.9.0rc1(但在0.8.1中也不起作用)
  • numpy 1.6.1

推荐答案

Resample has an base argument which covers this case:

ts.resample(rule='24H', closed='left', label='left', base=17).sum()

输出:

2012-01-01 17:00:00    24
2012-01-02 17:00:00    24
2012-01-03 17:00:00    12
Freq: 24H

这篇关于在特定的开始时间对每小时的TimeSeries重新采样的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆