时间序列数据被定义为提供在各个业务领域中使用的信息的重要来源。从传统的金融行业到教育行业,时间序列数据包含有关时间的许多详细信息。

时间序列预测是处理时间序列数据以通过时间序列建模预测未来值的机器学习建模。

Pandas具有处理各个领域的时间序列数据的广泛功能和特性。通过使用NumPy的datetime64timedelta64数据类型。Pandas已经整合了来自其他Python库(如scikits.timeseries)的各种功能,并为操作时间序列数据创建了大量的新功能。

例如,Pandas支持从各种来源和格式解析时间序列信息。

导入包和数据

在开始之前,您需要导入一些包,这将使用numpy,pandas,matplotlibseaborn

您可以通过在代码中添加%matplotlib inline将要绘制的图像附加到Jupyter Notebook,并且还可以通过使用sns.set()切换到Seaborn默认值:

# import packages  
import numpy as np  
import pandas as pd  
import matplotlib.pyplot as plt  
import seaborn as sns  
%matplotlib inline  
sns.set()  

日期和时间

Pandas提供了许多处理日期、时间、时间差和时间跨度的功能。它主要用于数据科学应用。

本机日期和时间:

我们有两个位于datetime模块中的本机日期和时间。我们还可以使用dateutil函数在日期和时间上执行许多有用的功能。您还可以从各种字符串格式解析日期:

示例1:

import pandas as pd     
# Create the dates with frequency     
info = pd.date_range('5/4/2013', periods = 8, freq ='S')     
info  

输出:

DatetimeIndex(['2013-05-04 00:00:00', '2013-05-04 00:00:01',
               '2013-05-04 00:00:02', '2013-05-04 00:00:03',
               '2013-05-04 00:00:04', '2013-05-04 00:00:05',
               '2013-05-04 00:00:06', '2013-05-04 00:00:07'],
              dtype='datetime64[ns]', freq='S')

示例2:

import pandas as pd   
# Create the Timestamp   
p = pd.Timestamp('2018-12-12 06:25:18')   
# Create the DateOffset   
do = pd.tseries.offsets.DateOffset(n = 2)   
# Print the Timestamp   
print(p)   
# Print the DateOffset   
print(do)  

输出:

2018-12-12 06:25:18
<2 * DateOffsets>

标签: Pandas, Pandas教程, Pandas库, Pandas基础, Pandas学习, Pandas使用, Pandas指南, Pandas入门教程, Pandas模块, Pandas数据库, Pandas实战教程, Pandas用法总结, Pandas文档