时间序列  ???? 索引

 

# 示例数据
import numpy as np
import pandas as pd
import datetime

times = pd.date_range('2019-1-1',periods=10,freq='MS')
ps = pd.Series(np.random.rand(len(times)),index=times)

#-----输出-----#
2019-01-01    0.374180
2019-02-01    0.354294
2019-03-01    0.098253
2019-04-01    0.509028
2019-05-01    0.943419
2019-06-01    0.619618
2019-07-01    0.736451
2019-08-01    0.695320
2019-09-01    0.607416
2019-10-01    0.506309
Freq: MS, dtype: float64

索引 (整数索引,索引和列表一样没有区别。) : 

ps[0]
ps[::2]
ps[:3]
ps['2019']
ps['2019-1']

#-----输出-----#
0.3741804976952492

2019-01-01    0.374180
2019-03-01    0.098253
2019-05-01    0.943419
2019-07-01    0.736451
2019-09-01    0.607416

2019-01-01    0.374180
2019-02-01    0.354294
2019-03-01    0.098253
Freq: MS, dtype: float64

2019-01-01    0.374180
2019-02-01    0.354294
2019-03-01    0.098253
2019-04-01    0.509028
2019-05-01    0.943419
2019-06-01    0.619618
2019-07-01    0.736451
2019-08-01    0.695320
2019-09-01    0.607416
2019-10-01    0.506309
Freq: MS, dtype: float64

2019-01-01    0.37418
Freq: MS, dtype: float64
View Code

相关文章: