pandas 时间序列resample
resample与groupby的区别:
resample:在给定的时间单位内重取样
groupby:对给定的数据条目进行统计
函数原型:
DataFrame.resample(rule, how=None, axis=0, fill_method=None, closed=None, label=None, convention='start', kind=None, loffset=None, limit=None, base=0)
其中,参数how已经废弃了。
下面开始练习
import numpy as np
import pandas as pd
Start by creating a series with 9 one minute timestamps.
index = pd.date_range('1/1/2000', periods=9, freq='T')
series = pd.Series(range(9), index=index)
Downsample the series into 3 minute bins and sum the values of the timestamps falling into a bin.
series.resample('3T').sum()
To include this value close the right side of the bin interval as illustrated in the example below this one.
series.resample('3T', label='right').sum()
Downsample the series into 3 minute bins as above, but close the right side of the bin interval.
series.resample('3T', label='right', closed='right').sum()
Upsample the series into 30 second bins.
series.resample('30S').asfreq()
Upsample the series into 30 second bins and fill the NaN values using the pad method.
series.resample('30S').pad()
Upsample the series into 30 second bins and fill the NaN values using the bfill method.
series.resample('30S').bfill()
Pass a custom function via apply
def custom_resampler(array_like):
return np.sum(array_like)+5 series.resample('3T').apply(custom_resampler)
附:常见时间频率
A year
M month
W week
D day
H hour
T minute
S second
pandas 时间序列resample的更多相关文章
- Pandas时间序列
Pandas时间序列 pandas 提供了一组标准的时间序列处理工具和数据算法 数据类型及操作 Python 标准库的 datetime datetime 模块中的 datetime. time. c ...
- Pandas 时间序列处理
目录 Pandas 时间序列处理 1 Python 的日期和时间处理 1.1 常用模块 1.2 字符串和 datetime 转换 2 Pandas 的时间处理及操作 2.1 创建与基础操作 2.2 时 ...
- pandas的resample重采样
Pandas中的resample,重新采样,是对原样本重新处理的一个方法,是一个对常规时间序列数据重新采样和频率转换的便捷的方法. 降采样:高频数据到低频数据 升采样:低频数据到高频数据 主要函数:r ...
- Pandas 时间序列
# 导入相关库 import numpy as np import pandas as pd 在做金融领域方面的分析时,经常会对时间进行一系列的处理.Pandas 内部自带了很多关于时间序列相关的工具 ...
- pandas时间序列常用操作
目录 一.时间序列是什么 二.时间序列的选取 三.时间序列的生成 四.时间序列的偏移量 五.时间前移或后移 五.时区处理 六.时期及算术运算 七.频率转换 一.时间序列是什么 时间序列在多个时间点观察 ...
- pandas时间序列学习笔记
目录 创建一个时间序列 pd.date_range() info() asfred() shifted(),滞后函数 diff()求差分 加减乘除 DataFrame.reindex() 通过data ...
- Python——Pandas 时间序列数据处理
介绍 Pandas 是非常著名的开源数据处理库,我们可以通过它完成对数据集进行快速读取.转换.过滤.分析等一系列操作.同样,Pandas 已经被证明为是非常强大的用于处理时间序列数据的工具.本节将介绍 ...
- Python Pandas 时间序列双轴折线图
时间序列pv-gmv双轴折线图 import numpy as np import pandas as pd import matplotlib.pyplot as plt n = 12 date_s ...
- pandas时间序列滑窗
时间序列数据统计-滑动窗口 窗口函数 import pandas as pd import numpy as np ser_obj = pd.Series(np.random.randn(1000), ...
随机推荐
- Android四大组件之BroadCast(续)
1.哪一个方法可以发送广播? activity.sendbroadcast or context.sentbroadcast or service.sendbroadcast 2.创建广播接受程序必须 ...
- Monyer's Game 0~5关过关方法
自从Monyer编写了这个通关小游戏,可谓是好事坏事参半吧! 好事是Monyer认识了许多电脑高手,包括netpatch.luoluo等,连LCX这种骨灰级选手也过来了,可谓是收获不小(所以既然我已经 ...
- Windows Form小技巧
如果需要将两个控件在窗体上使用Dock来进行布局时,会出现Dock.Fill不会占据Dock.Bottom之外空间的情况,这时可以设置Dock.Fill的控件BringToFront, 这样使得控件最 ...
- Effective Java 29 Consider typesafe heterogeneous containers
When a class literal is passed among methods to communicate both compile-time and runtime type infor ...
- hbase常用命令总结
创建表:表名:csliyb:testuser列族:name 例子:create 'csliyb:testuser','name','age' 添加记录: put 'csliyb:testuser',' ...
- 深度学习笔记------linux下配置安装caffe-cpu only模式
本文适合初学者学习配置caffe的最简单方法.这是我在看了网上各种大神的方法后总结的最傻瓜式的配置方法了. 本人也是在不断地配置caffe过程中受打击与成长@.@ 第一步.配置caffe所需的依赖环境 ...
- android使用微软雅黑字体
android使用微软雅黑字体,需要下载字体 ttf文件 下载地址:http://download.csdn.net/detail/xiaoliu123586/9049815 放在assert,然后引 ...
- selenium如何分别启动IE、firefox、chrome浏览器
1.火狐浏览器 /* * 初始化火狐浏览器 * */ public static WebDriver initFireFox(WebDriver dr) { String key = "we ...
- 【实践】获取CKEditor的html文本、纯文本、被选中的内容及赋值
<%=Html.TextAreaFor(Model => Model.WORK_INTRODUCTION)%> <script type="text/javasc ...
- 关于JS获取select值的两种实现方法
前几天发了一篇关于javascript获取select值的方法,后来发现有另一种实现方法,所以就都发出来比较一下: 方法一:通过获取option标签的value值来确定: <!DOCTYPE h ...