pandas时间序列操作

最好用的时间序列处理工具是pandas,它里面的各个主要的类继承了性能很好的np.datetime64,基于它构建的时间类型的数组能够实现快速的向量化运算。


pandas处理时间序列支持的功能

  • 解析来自各种来源和格式的时间序列信息
  • 生成固定频率日期和时间范围的序列
  • 使用时区信息处理和转换日期时间
  • 将时间序列重采样或转换为特定频率
  • 以绝对或相对时间增量执行日期和时间算术


概述

pandas捕捉了4个与时间相关的一般概念:

  1. 日期时间:具有时区支持特定日期和时间。与datetime.datetime标准库相似。

  2. 时间增量:绝对持续时间。与datetime.timedelta标准库相似。

  3. 时间跨度:由时间点及其关联的频率定义的时间跨度。

  4. 日期偏移量:尊重日历算术的相对持续时间。类似于dateutil.relativedelta.relativedeltadateutil包。

概念

标量类

数组类

pandass数据类型

主要创建方法

日期时间

Timestamp

DatetimeIndex

datetime64[ns];datetime64[ns, tz]

to_datetime;date_range

时间增量

Timedelta

TimedeltaIndex

timedelta64[ns]

to_timedelta;timedelta_range

时间跨度

Period

PeriodIndex

period[freq]

Period;period_range

日期偏移

DateOffset

None

None

DateOffse


*常用的时间序列构建与实例的操作(代码)*


时间戳、时间戳数组创建

https://nbviewer.jupyter.org/github/JoJoJohnSnow/JPnotes/blob/master/notes/%E6%97%B6%E9%97%B4%E6%88%B3%E3%80%81%E6%97%B6%E9%97%B4%E6%88%B3%E6%95%B0%E7%BB%84%E5%88%9B%E5%BB%BA.ipynb


时间序列索引

https://nbviewer.jupyter.org/github/JoJoJohnSnow/JPnotes/blob/master/notes/%E6%97%B6%E9%97%B4%E5%BA%8F%E5%88%97%E7%B4%A2%E5%BC%95.ipynb


时间序列实例的常用方法

https://github.com/JoJoJohnSnow/JPnotes/blob/master/notes/%E6%97%B6%E9%97%B4%E5%BA%8F%E5%88%97%E5%AE%9E%E4%BE%8B%E7%9A%84%E7%9B%B8%E5%85%B3%E6%96%B9%E6%B3%95.ipynb

posted @ 2020-04-07 17:12  MO_JOJOJO  阅读(487)  评论(0编辑  收藏  举报