时间序列

  • 时间戳 tiimestamp:固定的时刻 -> pd.Timestamp
  • 固定时期 period:比如 2016年3月份,再如2015年销售额 -> pd.Period
  • 时间间隔 interval:由起始时间和结束时间来表示,固定时期是时间间隔的一个特殊

时间日期在 Pandas 里的作用

  • 分析金融数据,如股票交易数据
  • 分析服务器日志

1.python里的datetime模块

python 标准库里提供了时间日期的处理模块,这个是时间日期的基础。
数据科学包10-pandas高级内容之时间序列

1)时间差

数据科学包10-pandas高级内容之时间序列

2)字符串和 datetime 转换

数据科学包10-pandas高级内容之时间序列

2.Pandas 里的时间序列

Pandas 里使用 Timestamp 来表达时间
数据科学包10-pandas高级内容之时间序列

3.日期范围

1)生成时间范围

数据科学包10-pandas高级内容之时间序列

2)时间频率

数据科学包10-pandas高级内容之时间序列

4时期及算术运算

pd.Period 表示时期,比如几日,月或几个月等。比如用来统计每个月的销售额,就可以用时期作为单位。
数据科学包10-pandas高级内容之时间序列

1)时间序列

数据科学包10-pandas高级内容之时间序列

2)时间的频率转换-asfreq

  • A-DEC: 以 12 月份作为结束的年时期
  • A-NOV: 以 11 月份作为结束的年时期
  • Q-DEC: 以 12 月份作为结束的季度时期
    数据科学包10-pandas高级内容之时间序列
    数据科学包10-pandas高级内容之时间序列

3)季度时间频率

Pandas 支持 12 种季度型频率,从 Q-JAN 到 Q-DEC
数据科学包10-pandas高级内容之时间序列

4)Timestamp和Period相互转换

数据科学包10-pandas高级内容之时间序列
数据科学包10-pandas高级内容之时间序列

5.重采样

  • 高频率 -> 低频率 -> 降采样:5 分钟股票交易数据转换为日交易数据
  • 低频率 -> 高频率 -> 升采样
  • 其他重采样:每周三 (W-WED) 转换为每周五 (W-FRI)

数据科学包10-pandas高级内容之时间序列
数据科学包10-pandas高级内容之时间序列

1)OHLC重采样

金融数据专用:Open/High/Low/Close

数据科学包10-pandas高级内容之时间序列

2)通过groupby重采样

数据科学包10-pandas高级内容之时间序列
数据科学包10-pandas高级内容之时间序列

3)升采样和插值

数据科学包10-pandas高级内容之时间序列
数据科学包10-pandas高级内容之时间序列

4)时间重采样

数据科学包10-pandas高级内容之时间序列
数据科学包10-pandas高级内容之时间序列

5)性能

数据科学包10-pandas高级内容之时间序列

6)时间日期解析

从文件中读取日期序列

数据科学包10-pandas高级内容之时间序列
数据科学包10-pandas高级内容之时间序列
数据科学包10-pandas高级内容之时间序列
数据科学包10-pandas高级内容之时间序列
数据科学包10-pandas高级内容之时间序列

自定义时间日期解析函数

数据科学包10-pandas高级内容之时间序列
数据科学包10-pandas高级内容之时间序列

相关文章:

  • 2021-12-02
  • 2021-05-25
  • 2021-08-12
  • 2022-12-23
  • 2022-12-23
  • 2021-05-21
猜你喜欢
  • 2021-10-06
  • 2021-10-17
  • 2021-12-17
  • 2021-04-20
  • 2021-08-15
  • 2021-10-04
  • 2022-12-23
相关资源
相似解决方案