将时序字符串转时间序列
df.time=pd.to_datetime
当我们把字符串转换成时间序列,并将其设置为索引后,就可以使用切片那获取任意时间段内的数据了
df.set_index('time',drop=True)
#按年来提数据
print(df['2018'])
df['2018':'2021']
#按月来提数据
df['2018-01']
df['2018-01':'2018-05']
#按天来提出数据
df['2018-05-24':'2018-09-27']
时间序列聚合resample
pandas时间序列加减Timedelta
Timedelta对象有属性:weeks、days、seconds、milliseconds、microseconds和nanoseconds
当创建一个Timelta后就能对已经存在的时间序列进行加减操作了
td=pd.Timedelta(weeks=2,days=10,hours=12,minutes=2.4,seconds=10.3)
df.time[0]+td
时间点Timestamp
now=pd.Timestamp.now()
附录
更多关于编程开发,数据分析,数据库等技术分享内容可以关注以下公众号一颗程序树