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()的更多相关文章

  1. Python数据分析(三)pandas resample 重采样

    下方是pandas中resample方法的定义,帮助文档http://pandas.pydata.org/pandas-docs/stable/timeseries.html#resampling中有 ...

  2. pandas 时间序列resample

    resample与groupby的区别:resample:在给定的时间单位内重取样groupby:对给定的数据条目进行统计 函数原型:DataFrame.resample(rule, how=None ...

  3. Pandas 基础(14) - DatetimeIndex and Resample

    这一小节要介绍两个内容, 一个是 DatetimeIndex 日期索引, 另一个是 Resample, 这是一个函数, 可以通过参数的设置, 来调整数据的查询条件, 从而得到不同的结果. 首先看下关于 ...

  4. pandas的resample重采样

    Pandas中的resample,重新采样,是对原样本重新处理的一个方法,是一个对常规时间序列数据重新采样和频率转换的便捷的方法. 降采样:高频数据到低频数据 升采样:低频数据到高频数据 主要函数:r ...

  5. pandas之时间序列(data_range)、重采样(resample)、重组时间序列(PeriodIndex)

    1.data_range生成时间范围 a) pd.date_range(start=None, end=None, periods=None, freq='D') start和end以及freq配合能 ...

  6. 10 Minutes to pandas

    摘要   一.创建对象 二.查看数据 三.选择和设置 四.缺失值处理 五.相关操作 六.聚合 七.重排(Reshaping) 八.时间序列 九.Categorical类型   十.画图      十一 ...

  7. 【转载】使用Pandas进行数据提取

    使用Pandas进行数据提取 本文转载自:蓝鲸的网站分析笔记 原文链接:使用python进行数据提取 目录 set_index() ix 按行提取信息 按列提取信息 按行与列提取信息 提取特定日期的信 ...

  8. 10分钟学习pandas

    10 Minutes to pandas This is a short introduction to pandas, geared mainly for new users. You can se ...

  9. pandas 透视表 pivot_table

    The function pandas.pivot_table can be used to create spreadsheet-style pivot tables. It takes a num ...

随机推荐

  1. 如何创建JAR文件?如何运行.jar形式的Java程序?

    一.如何创建JAR文件? .jar是用来压缩档案或者解压档案的文件格式,其特点是具有无损压缩的功能.想知道如何创建这种程序?请访问 http://www.cnblogs.com/yjmyzz/p/ex ...

  2. 操作LOG文件-删除log目录下,所有的空文件-删除5天前的文件

    # 1.logs目录下,有一部分文件是空的# 1.删除log目录下,所有的空文件# 2.删除5天前的文件 # 需求分析:# 1.os.walk()获取到所在以.log结尾的文件# 2.判断文件的大小, ...

  3. ThinkPHP连接主从数据库

    config.php文件设置如下: return array( 'URL_MODE'=>0,   'DB_TYPE'=>'mysql',   'DB_HOST'=>'localhos ...

  4. java游戏开发基础Swing之JRadioButton

    © 版权声明:本文为博主原创文章,转载请注明出处 1.按钮(JButton) Swing中的按钮是JButton,它是javax.swing.AbstractButton类的子类,Swing中的按钮可 ...

  5. thread.join() 方法存在的必要性是什么?

    好久远的问题,为什么关注这个问题的人这么少? 或许是用到这个功能的情形比较少吧. 1.等待处理结果 为什么要用join()方法在很多情况下,主线程生成并起动了子线程,如果子线程里要进行大量的耗时的运算 ...

  6. springBoot+springCloud学习笔记

    尊重原创:https://www.jianshu.com/p/492dfefa2735 SpringBoot 配置优先级 在命令行中传入的参数 如:java -jar storeMs.jar --se ...

  7. C# 接口中的索引器

    索引器可在 接口(C# 参考) 上声明.接口索引器的访问器与类索引器的访问器具有以下方面的不同: 接口访问器不使用修饰符. 接口访问器没有体. 因此,访问器的用途是指示索引器是读写.只读还是只写.以下 ...

  8. iOS 多网络请求同步并发

    iOS中经常会用到多线程,在多线程中有一个线程组的概念(group),创建多个线程组任务,多组任务都完成之后,就会进入dispatch_group_notify队列中. 同时多线程中还有一个信号量的概 ...

  9. redhat安装中文man手册

    1.下载中文man手册 http://download.chinaunix.net/download.php?id=13232&ResourceID=6537 2.上传至服务器并解压 tar ...

  10. 关于Java静态代码块、初始化块、构造函数的调用顺寻问题?

    public class ClassA { public ClassA(){ System.out.println("A 构造..."); } { System.out.print ...