Pandas 教程-Pandas时间序列
整理:python架构师
时间序列数据被定义为提供在各个业务领域中使用的信息的重要来源。从传统的金融行业到教育行业,时间序列数据包含有关时间的许多详细信息。
时间序列预测是处理时间序列数据以通过时间序列建模预测未来值的机器学习建模。
Pandas具有处理各个领域的时间序列数据的广泛功能和特性。通过使用NumPy的datetime64和timedelta64数据类型。Pandas已经整合了来自其他Python库(如scikits.timeseries)的各种功能,并为操作时间序列数据创建了大量的新功能。
例如,Pandas支持从各种来源和格式解析时间序列信息。
导入包和数据
在开始之前,您需要导入一些包,这将使用numpy,pandas,matplotlib和seaborn。
# import packagesimport numpy as npimport pandas as pdimport matplotlib.pyplot as pltimport seaborn as sns%matplotlib inlinesns.set()
👉点击领取:最全Python资料合集
日期和时间
Pandas提供了许多处理日期、时间、时间差和时间跨度的功能。它主要用于数据科学应用。
本机日期和时间:
我们有两个位于datetime模块中的本机日期和时间。我们还可以使用dateutil函数在日期和时间上执行许多有用的功能。您还可以从各种字符串格式解析日期:
示例1:
import pandas as pd# Create the dates with frequencyinfo = 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 Timestampp = pd.Timestamp('2018-12-12 06:25:18')# Create the DateOffsetdo = pd.tseries.offsets.DateOffset(n = 2)# Print the Timestampprint(p)# Print the DateOffsetprint(do)
2018-12-12 06:25:18<2 * DateOffsets>
热门推荐