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 祝福语驱散霉运的话简短