时间序列基础
In [1]: from datetime import datetime
In [2]: dates = [datetime(2011,1,2),datetime(2011,1,5),datetime(2011,1,7),datetime(2011,1,8),datetime(2011,1,10),dateti
...: me(2011,1,12)]
In [3]: import numpy as np
In [4]: import pandas as pd
In [5]: ts = pd.Series(np.random.randn(6),index = dates)
In [6]: ts
Out[6]:
2011-01-02 0.022420
2011-01-05 2.527062
2011-01-07 -1.802058
2011-01-08 0.176907
2011-01-10 -2.010576
2011-01-12 -1.147277
dtype: float64
这些datetime对象实际时被放到DatetimeIndex中的
ts是一个Series对象,可以对其进行算数运算。
In [9]: type(ts)
Out[9]: pandas.core.series.Series
In [10]: ts2 = ts[::2]
In [11]: ts+ts2
Out[11]:
2011-01-02 0.044841
2011-01-05 NaN
2011-01-07 -3.604117
2011-01-08 NaN
2011-01-10 -4.021151
2011-01-12 NaN
dtype