pandas中的resample的参数

来源:互联网 发布:数控折弯机怎样编程 编辑:程序博客网 时间:2024/06/16 20:09
用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.1166292011-01-05   -1.3851272011-01-08    1.5010062011-01-09    1.1157872011-01-10    0.5234722011-01-12    1.522763dtype: float64
ts.resample('D', fill_method='ffill')
Out[27]:
2011-01-02    0.1166292011-01-03    0.1166292011-01-04    0.1166292011-01-05   -1.3851272011-01-06   -1.3851272011-01-07   -1.3851272011-01-08    1.5010062011-01-09    1.1157872011-01-10    0.5234722011-01-11    0.5234722011-01-12    1.522763Freq: D, dtype: float64
In [28]:
ts.resample('D', fill_method='bfill')

Out[28]:
2011-01-02    0.1166292011-01-03   -1.3851272011-01-04   -1.3851272011-01-05   -1.3851272011-01-06    1.5010062011-01-07    1.5010062011-01-08    1.5010062011-01-09    1.1157872011-01-10    0.5234722011-01-11    1.5227632011-01-12    1.522763Freq: D, dtype: float64
B       business day frequencyC       custom business day frequency (experimental)D       calendar day frequencyW       weekly frequencyM       month end frequencyBM      business month end frequencyCBM     custom business month end frequencyMS      month start frequencyBMS     business month start frequencyCBMS    custom business month start frequencyQ       quarter end frequencyBQ      business quarter endfrequencyQS      quarter start frequencyBQS     business quarter start frequencyA       year end frequencyBA      business year end frequencyAS      year start frequencyBAS     business year start frequencyBH      business hour frequencyH       hourly frequencyT       minutely frequencyS       secondly frequencyL       milliseondsU       microsecondsN       nanoseconds

0 0