pandas 下采样和上采样
示例
import pandas as pd
import numpy as np
np.random.seed(0)
rng = pd.date_range('2015-02-24', periods=10, freq='T')
df = pd.DataFrame({'Val' : np.random.randn(len(rng))}, index=rng)
print (df)
Val
2015-02-24 00:00:00 1.764052
2015-02-24 00:01:00 0.400157
2015-02-24 00:02:00 0.978738
2015-02-24 00:03:00 2.240893
2015-02-24 00:04:00 1.867558
2015-02-24 00:05:00 -0.977278
2015-02-24 00:06:00 0.950088
2015-02-24 00:07:00 -0.151357
2015-02-24 00:08:00 -0.103219
2015-02-24 00:09:00 0.410599#downsampling with aggregating sum
print (df.resample('5Min').sum())
Val
2015-02-24 00:00:00 7.251399
2015-02-24 00:05:00 0.128833
#5Min is same as 5T
print (df.resample('5T').sum())
Val
2015-02-24 00:00:00 7.251399
2015-02-24 00:05:00 0.128833
#upsampling and fill NaN values method forward filling
print (df.resample('30S').ffill())
Val
2015-02-24 00:00:00 1.764052
2015-02-24 00:00:30 1.764052
2015-02-24 00:01:00 0.400157
2015-02-24 00:01:30 0.400157
2015-02-24 00:02:00 0.978738
2015-02-24 00:02:30 0.978738
2015-02-24 00:03:00 2.240893
2015-02-24 00:03:30 2.240893
2015-02-24 00:04:00 1.867558
2015-02-24 00:04:30 1.867558
2015-02-24 00:05:00 -0.977278
2015-02-24 00:05:30 -0.977278
2015-02-24 00:06:00 0.950088
2015-02-24 00:06:30 0.950088
2015-02-24 00:07:00 -0.151357
2015-02-24 00:07:30 -0.151357
2015-02-24 00:08:00 -0.103219
2015-02-24 00:08:30 -0.103219
2015-02-24 00:09:00 0.410599
热门推荐
10 祝女儿简短祝福语大全
11 大学新年祝福语简短创意
12 元旦适合的祝福语简短
13 朋友出远门祝福语简短
14 初六简短的祝福语
15 祝男孩生日祝福语简短
16 同事调离的祝福语简短
17 拜年红包的祝福语简短
18 妈妈生日祝福语简短励志