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. 【HTML5】元素<head>的使用

    功能描述 在新建的页面<head>元素中,加入该元素所包含的各类标签,并定义超级链接的样式.当单击"请点击我"标签时,并展示相应效果并进入<base>元素设 ...

  2. Memcache遍历查询所有键值的方法

    直接举个Telnet命令行下遍历memcached所有key的方法:   stats items STAT items:7:number1 STATitems:7:age188 END stats c ...

  3. python常见面试题(二)

    1. 到底什么是Python?你可以在回答中与其他技术进行对比(也鼓励这样做). 下面是一些关键点: Python是一种解释型语言.这就是说,与C语言和C的衍生语言不同,Python代码在运行之前不需 ...

  4. Verilog 浮点数运算模块

    算法中常常会到浮点数运算,而浮点数的处理常常是Verilog初学中常常遇到的问题.以下将就一个简单的例子说明Verilog中浮点数运算处理. 在JPEG图像压缩时遇到色彩空间变换的问题,将YCbCr转 ...

  5. Verilog利用$fdisplay命令往文件中写入数据

    最近在做的事情是,用FPGA生成一些满足特定分布的序列.因此为了验证我生成的序列是否拥有预期的性质,我需要将生成的数据提取出来并且放到MATLAB中做数据分析. 但是网上的程序很乱,表示看不懂==其实 ...

  6. kubernetes高级之动态准入控制

    系列目录 动态准入控制器文档介绍了如何使用标准的,插件式的准入控制器.但是,但是由于以下原因,插件式的准入控制器在一些场景下并不灵活: 它们需要编译到kube-apiserver里 它们仅在apise ...

  7. JavaScript的toString()

    JavaScript toString() 方法 JavaScript Boolean 对象 定义和用法 toString() 方法可把一个逻辑值转换为字符串,并返回结果. 语法 booleanObj ...

  8. 启动 ./spark-shell 命令报错

    当使用./spark-shell 命令报错 Caused by: ERROR XJ040: Failed to start database @476fde05, see the next excep ...

  9. oracle分区表和分区索引概述

    ㈠ 分区表技术概述            ⑴ Range 分区            ① 例子                  create table t         (...列定义...)  ...

  10. static 修饰的变量在程序中容易出现的问题

    package lianxi; public class StaticTest {    int a = 0;    static int b =0;    StaticTest(){         ...