📅  最后修改于: 2020-10-29 04:45:37             🧑  作者: Mango
时间序列数据被定义为重要的信息来源,该信息提供了可用于各种业务的策略。从传统的金融业到教育业,它包含许多有关时间的细节。
时间序列预测是一种处理时间序列数据的机器学习模型,用于通过时间序列建模预测未来值。
Pandas 具有与所有域的时间序列数据一起使用的广泛功能。通过使用NumPy datetime64和timedelta64 dtypes。 Pandas整合了与其他Python库(如scikits.timeseries)不同的功能,并创建了大量用于处理时间序列数据的新功能。
例如,Pandas 支持从各种来源和格式解析时间序列信息。
开始之前,您必须导入一些使用numpy,pandas,matplotlib和seaborn的软件包。
您可以通过在代码中添加%matplotlib内联代码来附加要在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函数,我们还可以在日期和时间上执行许多有用的功能。您还可以使用多种字符串格式解析日期:
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')
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>