pandas 时间序列分析(一)—— 基础

0. 以时间作为序列的索引

>> from datetime import datetime
>> dates = [datetime(2011, 1, i) for i in [2, 5, 7, 8, 10, 12]]
>> ts = pd.Series(np.random.randn(6), index=dates)
>> ts
2011-01-02   -1.157516
2011-01-05    0.755876
2011-01-07    0.299113
2011-01-08    0.446367
2011-01-10   -1.700069
2011-01-12    0.261344
dtype: float64

进一步查看 ts 的成员:

>> type(ts)
pandas.core.series.Series
>> ts.index
...
>> ts.index.dtype
dtype('<M8[ns]')            # 这是对于小端机的结果;

>> ts.index[0]
Timestamp('2011-01-02 00:00:00')
原文地址:https://www.cnblogs.com/mtcnn/p/9421720.html