时间序列
resample函数的用法:
In [14]: rng = pd.date_range('1/1/2012', periods=100, freq='S')
In [15]: ts = pd.Series(np.random.randint(0, 500, len(rng)), index=rng)
#以五分钟为间隔,并加总。由于是随机生成的,所以每次结果可能不同
In [16]: ts.resample('5Min').sum()
Out[16]:
2012-01-01 25820
Freq: 5T, dtype: int32
In [17]: ttt = pd.date_range('1/1/2017', periods=12, freq='T')
In [18]: sss = pd.Series(range(12), index=ttt)
In [19]: sss
Out[19]:
2017-01-01 00:00:00 0
2017-01-01 00:01:00 1
2017-01-01 00:02:00 2
2017-01-01 00:03:00 3
2017-01-01 00:04:00 4
2017-01-01 00:05:00 5
2017-01-01 00:06:00 6
2017-01-01 00:07:00 7
2017-01-01 00:08:00 8
2017-01-01 00:09:00 9
2017-01-01 00:10:00 10
2017-01-01 00:11:00 11
Freq: T, dtype: int64
# 此间隔与下一个间隔之间的值的和
In [21]: sss.resample('3T').sum()
Out[21