pandas中的resample的参数

用resample可以很容易的筛选dataframe格式的数据的时间戳
例如:
 
 
dates = [datetime(2011, 1, 2), datetime(2011, 1, 5), 
         datetime(2011, 1, 8), datetime(2011, 1, 9), 
         datetime(2011, 1, 10), datetime(2011, 1, 12)]
In [17]:
ts = pd.Series(np.random.randn(6), index=dates)
In [18]:
ts
Out[18]:
2011-01-02    0.116629
2011-01-05   -1.385127
2011-01-08    1.501006
2011-01-09    1.115787
2011-01-10    0.523472
2011-01-12    1.522763
dtype: float64
ts.resample('D', fill_method='ffill')
Out[27]:
2011-01-02    0.116629
2011-01-03    0.116629
2011-01-04    0.116629
2011-01-05   -1.385127
2011-01-06   -1.385127
2011-01-07   -1.385127
2011-01-08    1.501006
2011-01-09    1.115787
2011-01-10    0.523472
2011-01-11    0.523472
2011-01-12    1.522763
Freq: D, dtype: float64
In [28]:
ts.resample('D', fill_method='bfill')

Out[28]:
2011-01-02    0.116629
2011-01-03   -1.385127
2011-01-04   -1.385127
2011-01-05   -1.385127
2011-01-06    1.501006
2011-01-07    1.501006
2011-01-08    1.501006
2011-01-09    1.115787
2011-01-10    0.523472
2011-01-11    1.522763
2011-01-12    1.522763
Freq: D, dtype: float64
 
B       business day frequency
C       custom business day frequency (experimental)
D       calendar day frequency
W       weekly frequency
M       month end frequency
BM      business month end frequency
CBM     custom business month end frequency
MS      month start frequency
BMS     business month start frequency
CBMS    custom business month start frequency
Q       quarter end frequency
BQ      business quarter endfrequency
QS      quarter start frequency
BQS     business quarter start frequency
A       year end frequency
BA      business year end frequency
AS      year start frequency
BAS     business year start frequency
BH      business hour frequency
H       hourly frequency
T       minutely frequency
S       secondly frequency
L       milliseonds
U       microseconds
N       nanoseconds

  • 5
    点赞
  • 13
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值