按自定义年度频率重新采样 [英] Resample by custom annual frequency
本文介绍了按自定义年度频率重新采样的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我知道我可以从7月1日开始每年使用AS-JUL进行重新采样,但是如何在不同的日期进行采样?
I know I can use AS-JUL to resample annually starting in July 1st, but how can I do by a different date?
In [11]: df
Out[11]:
value
date
2005-07-02 4
2005-09-20 7
2005-11-12 4
2005-12-31 0
2006-07-03 5
2006-06-25 6
2006-07-23 1
2006-09-28 8
2006-12-21 1
2006-12-27 9
2007-07-03 7
2007-09-21 0
In [12]: df.resample("AS-JUL").sum()
Out[12]:
value
date
2005-07-01 26
2006-07-01 19
2007-07-01 7
我希望开始日期为7月5日,如何在此之前重新采样?
I want the start date to be the 5th July, how can I resample by that?
推荐答案
您可以减去4天,重新采样,然后再添加4天...但这真是太可怕了:
You could subtract 4 days, resample, then add the 4 days back... but this is kind of horrible:
In [11]: data2.index = data2.index - pd.offsets.Day(4)
In [12]: res = data2.resample("AS-JUL").sum()
In [13]: res.index = res.index + pd.offsets.Day(4)
In [14]: res
Out[14]:
value
date
2004-07-05 4
2005-07-05 22
2006-07-05 26
2007-07-05 12
这篇关于按自定义年度频率重新采样的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文