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 同事调动的祝福语简短