pandas.resample()
http://www.cnblogs.com/hhh5460/p/5596340.html
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()的更多相关文章
- Python数据分析(三)pandas resample 重采样
下方是pandas中resample方法的定义,帮助文档http://pandas.pydata.org/pandas-docs/stable/timeseries.html#resampling中有 ...
- pandas 时间序列resample
resample与groupby的区别:resample:在给定的时间单位内重取样groupby:对给定的数据条目进行统计 函数原型:DataFrame.resample(rule, how=None ...
- Pandas 基础(14) - DatetimeIndex and Resample
这一小节要介绍两个内容, 一个是 DatetimeIndex 日期索引, 另一个是 Resample, 这是一个函数, 可以通过参数的设置, 来调整数据的查询条件, 从而得到不同的结果. 首先看下关于 ...
- pandas的resample重采样
Pandas中的resample,重新采样,是对原样本重新处理的一个方法,是一个对常规时间序列数据重新采样和频率转换的便捷的方法. 降采样:高频数据到低频数据 升采样:低频数据到高频数据 主要函数:r ...
- pandas之时间序列(data_range)、重采样(resample)、重组时间序列(PeriodIndex)
1.data_range生成时间范围 a) pd.date_range(start=None, end=None, periods=None, freq='D') start和end以及freq配合能 ...
- 10 Minutes to pandas
摘要 一.创建对象 二.查看数据 三.选择和设置 四.缺失值处理 五.相关操作 六.聚合 七.重排(Reshaping) 八.时间序列 九.Categorical类型 十.画图 十一 ...
- 【转载】使用Pandas进行数据提取
使用Pandas进行数据提取 本文转载自:蓝鲸的网站分析笔记 原文链接:使用python进行数据提取 目录 set_index() ix 按行提取信息 按列提取信息 按行与列提取信息 提取特定日期的信 ...
- 10分钟学习pandas
10 Minutes to pandas This is a short introduction to pandas, geared mainly for new users. You can se ...
- pandas 透视表 pivot_table
The function pandas.pivot_table can be used to create spreadsheet-style pivot tables. It takes a num ...
随机推荐
- java统计中英文字数 Java问题通用解决代码
http://yangchao20020.blog.163.com/blog/static/483822472011111635424751/ 这个不适用于新浪微博字数的统计,结果有差别,若需要可 ...
- 类中的internal成员可能是一种坏味道
前言 最近除了搞ASP.NET MVC之外,我也在思考一些编程实践方面的问题.昨天在回家路上,我忽然对一个问题产生了较为清晰的认识.或者说,原先只是有一丝细微的感觉,而现在将它和一些其他的方面进行了联 ...
- java之UDP(datagramsocket,datagramPacket)实例
import java.net.DatagramPacket; import java.net.DatagramSocket; import java.net.InetAddress; import ...
- iOS Masonry 抗压缩 抗拉伸
约束优先级: 在Autolayout中每个约束都有一个优先级, 优先级的范围是1 ~ 1000.创建一个约束,默认的优先级是最高的1000 Content Hugging Priority: 该优先级 ...
- 跳转 nginx 跳转 apache跳转
公司在google上投广告,需要做一些很简单的站去google上投广告,当用户在google上点击那些很简单的网站的时候,就会跳转到真实的网站.但是,如果用户直接在浏览器输入域名,并访问的话,那样就不 ...
- memcached使用总结
我的linux版本信息:Linux version 4.4.0-78-generic (buildd@lgw01-11) (gcc version 5.4.0 20160609 (Ubuntu 5.4 ...
- pip安装错误,用镜像
Retrying (Retry(total=4, connect=None, read=None, redirect=None)) after connection broken by 'Connec ...
- ASP.NET动态网站制作(23)-- ADO.NET(2)
前言:这节课老师请高级班的E老师过来代课,还是接着老师讲的内容继续深入,修改了上节课老师写的部分代码. 内容: 1.数据库本质就是一个软件,这个软件帮助我们把数据有序地存储起来,当我们需要数据的时候帮 ...
- C语言中的编译时分配内存
1.栈区(stack) --编译器自动分配释放,主要存放函数的参数值,局部变量值等: 2.堆区(heap) --由程序员分配释放: 3.全局区或静态区 --存放全局变量和静态变量:程序结束时由系统释放 ...
- j2EE的web.xml详解
https://blog.csdn.net/changqing5818/article/details/49928231 https://www.cnblogs.com/ClassNotFoundEx ...