重采样:指的是将时间序列从一个频率转化为另一个频率进行处理的过程,将高频率数据转化为低频率数据为降采样,低频率转化为高频率为升采样 pandas提供了一个resample的方法来帮助我们实现频率转化
#!usr/bin/env python
#-*- coding:utf-8 _*-
'''
@author:Administrator
@file: pandas_resample_demo.py
@time: 2020-01-05 下午 6:01
'''
import pandas as pd;
import numpy as np
t=pd.DataFrame(np.random.uniform(10,50,(100,1)),index=pd.date_range("20170101",periods=100))
print(t)
#以月统计数
r=t.resample("M").mean();
print(r)
#以10天统计
r=t.resample("10D").mean();
print(r)
0
2017-01-01 20.356330
2017-01-02 20.488090
2017-01-03 31.938724
2017-01-04 12.534453
2017-01-05 21.598071
... ...
2017-04-06 36.469250
2017-04-07 32.153706
2017-04-08 43.284973
2017-04-09 48.458640
2017-04-10 23.588089
[100 rows x 1 columns]
0
2017-01-31 30.333991
2017-02-28 29.471237
2017-03-31 32.540707
2017-04-30 32.148318
0
2017-01-01 22.969510
2017-01-11 35.790392
2017-01-21 31.502075
2017-01-31 32.797927
2017-02-10 25.763262
2017-02-20 31.012892
2017-03-02 34.761240
2017-03-12 33.079958
2017-03-22 29.753773
2017-04-01 32.148318