有时候时间序列的原始数据不完整,不连贯,需要进一步整理,填充才能继续使用。
一、datetime的使用。设置一个时间区间段,并作为行索引,可以如下设置
times = pd.date_range(start="19890101", end="20220201", freq="MS")
times特性如下:
times.info(),times
<class 'pandas.core.frame.DataFrame'>
RangeIndex: 398 entries, 0 to 397
Data columns (total 1 columns):
# Column Non-Null Count Dtype
--- ------ -------------- -----
0 date 398 non-null datetime64[ns]
dtypes: datetime64[ns](1)
memory usage: 3.2 KB
None date
0 1989-01-01
1 1989-02-01
2 1989-03-01
3 1989-04-01
4 1989-05-01
..
本文介绍了如何利用Python处理时间序列数据,包括设置datetime时间区间作为行索引,使用date_range函数生成时间序列,以及将不完整的数据转换为datetime类型。在数据合并过程中,使用pd.merge进行左连接,并删除全为空的数据列,以实现时间序列数据的完整性和一致性。
订阅专栏 解锁全文
647

被折叠的 条评论
为什么被折叠?



