没有合适的资源?快使用搜索试试~ 我知道了~
Pandas处理时序数据(初学者必会)!1
需积分: 0 0 下载量 37 浏览量
2022-08-04
14:50:33
上传
评论
收藏 1.44MB PDF 举报
温馨提示
![preview](https://dl-preview.csdnimg.cn/86330501/0001-c8d9e91dab3ee27078f42fc73b5e259a_thumbnail.jpeg)
![preview-icon](https://csdnimg.cn/release/downloadcmsfe/public/img/scale.ab9e0183.png)
试读
25页
1. 时序的创建 2. 时序的索引及属性 3. 重采样 4. 窗口函数 5. 问题及练习
资源详情
资源评论
资源推荐
![](https://csdnimg.cn/release/download_crawler_static/86330501/bg1.jpg)
2020/7/11 Pandas处理时序数据(初学者必会)!
https://mp.weixin.qq.com/s?__biz=MzIyNjM2MzQyNg==&tempkey=MTA2OV92RzVNRVMwa0hGUzk4OUg2Z25Bc3RQNnZNQlFuZXdZb0hUbz
…
1/25
Pandas处理时序数据(初学者必会)!
↑↑↑关注后"星标"Datawhale
每日干货 & 每月组队学习,不错过
Datawhale干货
作者:耿远昊,Datawhale成员,华东师范大学
时序数据是指时间序列数据。时间序列数据是同一统一指标按时间顺序记录的数据列。在同一数据列
中的各个数据必须是同口径的,要求具有可比性。时序数据可以是时期数,也可以时点数。
时间序列分析的目的是通过找出样本内时间序列的统计特性和发展规律性,构建时间序列模型,进行
样本外预测。
现在,一起来学习用Pandas处理时序数据。
本文目录
1. 时序的创建
1.1. 四类时间变量
1.2. 时间点的创建
1.3. DataOffset对象
2. 时序的索引及属性
2.1. 索引切片
2.2. 子集索引
2.3. 时间点的属性
3. 重采样
3.1. resample对象的基本操作
3.2. 采样聚合
耿远昊 今天Datawhale
![](https://csdnimg.cn/release/download_crawler_static/86330501/bg2.jpg)
2020/7/11 Pandas处理时序数据(初学者必会)!
https://mp.weixin.qq.com/s?__biz=MzIyNjM2MzQyNg==&tempkey=MTA2OV92RzVNRVMwa0hGUzk4OUg2Z25Bc3RQNnZNQlFuZXdZb0hUbz
…
2/25
3.3. 采样组的迭代
4. 窗口函数
4.1. Rolling
4.2. Expanding
5. 问题及练习
5.1. 问题
5.2. 练习
一、时序的创建
1.1. 四类时间变量
现在理解可能关于③和④有些困惑,后面会作出一些说明
1.2. 时间点的创建
(a)to_datetime方法
Pandas在时间点建立的输入格式规定上给了很大的自由度,下面的语句都能正确建立同一时间点
1
2
import pandas as pd
import numpy as np
1
2
3
4
5
6
7
8
9
10
11
12
13
14
pd.to_datetime('2020.1.1')
pd.to_datetime('2020 1.1')
pd.to_datetime('2020 1 1')
pd.to_datetime('2020 1-1')
pd.to_datetime('2020-1 1')
pd.to_datetime('2020-1-1')
pd.to_datetime('2020/1/1')
pd.to_datetime('1.1.2020')
pd.to_datetime('1.1 2020')
pd.to_datetime('1 1 2020')
pd.to_datetime('1 1-2020')
pd.to_datetime('1-1 2020')
pd.to_datetime('1-1-2020')
pd.to_datetime('1/1/2020')
![](https://csdnimg.cn/release/download_crawler_static/86330501/bg3.jpg)
2020/7/11 Pandas处理时序数据(初学者必会)!
https://mp.weixin.qq.com/s?__biz=MzIyNjM2MzQyNg==&tempkey=MTA2OV92RzVNRVMwa0hGUzk4OUg2Z25Bc3RQNnZNQlFuZXdZb0hUbz
…
3/25
Timestamp('2020-01-01 00:00:00')
下面的语句都会报错
此时可利用format参数强制匹配
Timestamp('2020-01-01 00:00:00')
同时,使用列表可以将其转为时间点索引
pandas.core.indexes.datetimes.DatetimeIndex
对于DataFrame而言,如果列已经按照时间顺序排好,则利用to_datetime可自动转换
(b)时间精度与范围限制
15
16
pd.to_datetime('20200101')
pd.to_datetime('2020.0101')
1
2
3
4
#pd.to_datetime('2020\\1\\1')
#pd.to_datetime('2020`1`1')
#pd.to_datetime('2020.1 1')
#pd.to_datetime('1 1.2020')
1
2
3
4
pd.to_datetime('2020\\1\\1',format='%Y\\%m\\%d')
pd.to_datetime('2020`1`1',format='%Y`%m`%d')
pd.to_datetime('2020.1 1',format='%Y.%m %d')
pd.to_datetime('1 1.2020',format='%d %m.%Y')
1
pd.Series(range(2),index=pd.to_datetime(['2020/1/1','2020/1/2']))
1
type(pd.to_datetime(['2020/1/1','2020/1/2']))
1
2
df = pd.DataFrame({'year': [2020, 2020],'month': [1, 1], 'day': [1, 2]})
pd.to_datetime(df)
![](https://csdnimg.cn/release/download_crawler_static/86330501/bg4.jpg)
2020/7/11 Pandas处理时序数据(初学者必会)!
https://mp.weixin.qq.com/s?__biz=MzIyNjM2MzQyNg==&tempkey=MTA2OV92RzVNRVMwa0hGUzk4OUg2Z25Bc3RQNnZNQlFuZXdZb0hUbz
…
4/25
事实上,Timestamp的精度远远不止day,可以最小到纳秒ns
Timestamp('2020-01-01 00:00:00.123456789')
同时,它带来范围的代价就是只有大约584年的时间点是可用的
Timestamp('1677-09-21 00:12:43.145225')
Timestamp('2262-04-11 23:47:16.854775807')
(c)date_range方法
一般来说,start/end/periods(时间点个数)/freq(间隔方法)是该方法最重要的参数,给定了其中
的3个,剩下的一个就会被确定
其中freq参数有许多选项,下面将常用部分罗列如下,更多选项可看这里
1
pd.to_datetime('2020/1/1 00:00:00.123456789')
1
pd.Timestamp.min
1
pd.Timestamp.max
1
pd.date_range(start='2020/1/1',end='2020/1/10',periods=3)
1
pd.date_range(start='2020/1/1',end='2020/1/10',freq='D')
1
pd.date_range(start='2020/1/1',periods=3,freq='D')
1
pd.date_range(end='2020/1/3',periods=3,freq='D')
剩余24页未读,继续阅读
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![docx](https://img-home.csdnimg.cn/images/20210720083331.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![avatar](https://profile-avatar.csdnimg.cn/8bea0dde30b140e199236eb7cf9bc5b7_weixin_35833704.jpg!1)
彥爷
- 粉丝: 20
- 资源: 311
上传资源 快速赚钱
我的内容管理 展开
我的资源 快来上传第一个资源
我的收益
登录查看自己的收益我的积分 登录查看自己的积分
我的C币 登录后查看C币余额
我的收藏
我的下载
下载帮助
![voice](https://csdnimg.cn/release/downloadcmsfe/public/img/voice.245cc511.png)
![center-task](https://csdnimg.cn/release/downloadcmsfe/public/img/center-task.c2eda91a.png)
最新资源
- Linux常用命令及用法说明
- 基于Matlab的FFT频谱分析及IIR数字滤波器设计
- AutoCAD高压低压电气开关柜设备接线图图纸
- AutoCAD电气图纸建筑电气开关柜常用cad图纸
- 使用ASP.NET Core和Entity Framework Core来构建一个基本的进销存系统.rar
- 深度学习经典数据集+FER2013面部表情识别+附带使用方法的python代码
- Python中,要实现连接多个相机并识别多个二维码.rar
- 使用FFT算法对一个信号进行分析.rar
- 171cms游戏应用下载系统源码.zip
- 基于jsp+servlet+mysql蛋糕甜品店购物网站源码+数据库(期末大作业).zip
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
![feedback](https://img-home.csdnimg.cn/images/20220527035711.png)
![feedback](https://img-home.csdnimg.cn/images/20220527035711.png)
![feedback-tip](https://img-home.csdnimg.cn/images/20220527035111.png)
安全验证
文档复制为VIP权益,开通VIP直接复制
![dialog-icon](https://csdnimg.cn/release/downloadcmsfe/public/img/green-success.6a4acb44.png)
评论0