Pandas —— 时间序列TimeSeries或TimeDataFrame的索引

时间序列TimeSeries的索引

In [48]: ts
Out[48]:
2011-01-02    0.711405
2011-01-05   -1.675175
2011-01-07    1.104304
dtype: float64

通过标签进行索引

In [50]: ts[1]
Out[50]: -1.6751745478946134

通过字符串进行索引

In [51]: ts['2011-01-07']
Out[51]: 1.1043041797936226

In [52]: ts['2011-01-05':]
Out[52]:
2011-01-05   -1.675175
2011-01-07    1.104304
dtype: float64

通过部分字符串进行索引

In [53]: ts['2011-01']
Out[53]:
2011-01-02    0.711405
2011-01-05   -1.675175
2011-01-07    1.104304
dtype: float64

通过时间戳进行索引

In [59]: ts[datetime(2011,1,7)]
Out[59]: 1.1043041797936226

TimeDataFrame的索引

方法跟TimeSeries类似,但需要加上loc()或iloc()才能访问到对应的数据,具体可参考Pandas —— loc( )和iloc( )

你可能感兴趣的:(Pandas)