Pandas中resample方法詳解
Pandas中的resample,重新取樣,是對原樣本重新處理的一個方法,是一個對常規時間序列資料重新取樣和頻率轉換的便捷的方法。
方法的格式是:
DataFrame.resample(rule, how=None, axis=0, fill_method=None, closed=None, label=None, convention='start',kind
=None, loffset=None, limit=None, base=0)
引數詳解是:
Parameters: |
rule : string
axis : int, optional, default 0 closed : {‘right’, ‘left’}
label : {‘right’, ‘left’}
convention : {‘start’, ‘end’, ‘s’, ‘e’} loffset : timedelta
base : int, default 0
|
---|
>>> index降低取樣頻率為三分鐘= pd.date_range('1/1/2000', periods=9, freq='T') >>> series = pd.Series(range(9), index=index) >>> series 2000-01-01 00:00:00 0 2000-01-01 00:01:00 1 2000-01-01 00:02:00 2 2000-01-01 00:03:00 3 2000-01-01 00:04:00 4 2000-01-01 00:05:00 5 2000-01-01 00:06:00 6 2000-01-01 00:07:00 7 2000-01-01 00:08:00 8 Freq: T, dtype: int64
>>>降低取樣頻率為三分鐘,但是每個標籤使用right來代替left。請注意,bucket中值的用作標籤。series.resample('3T').sum() 2000-01-01 00:00:00 3 2000-01-01 00:03:00 12 2000-01-01 00:06:00 21 Freq: 3T, dtype: int64
>>> series.resample('3T', label='right').sum() 2000-01-01 00:03:00 3 2000-01-01 00:06:00 12 2000-01-01 00:09:00 21 Freq: 3T, dtype: int64降低取樣頻率為三分鐘,但是關閉right區間。
>>> series.resample('3T', label='right', closed='right').sum() 2000-01-01 00:00:00 0 2000-01-01 00:03:00 6 2000-01-01 00:06:00 15 2000-01-01 00:09:00 15 Freq: 3T, dtype: int64增加取樣頻率到30秒
>>> series.resample('30S').asfreq()[0:5] #select first 5 rows 2000-01-01 00:00:00 0 2000-01-01 00:00:30 NaN 2000-01-01 00:01:00 1 2000-01-01 00:01:30 NaN 2000-01-01 00:02:00 2 Freq: 30S, dtype: float64增加取樣頻率到30S,使用pad方法填充nan值。
>>> series.resample('30S').pad()[0:5] 2000-01-01 00:00:00 0 2000-01-01 00:00:30 0 2000-01-01 00:01:00 1 2000-01-01 00:01:30 1 2000-01-01 00:02:00 2 Freq: 30S, dtype: int64增加取樣頻率到30S,使用bfill方法填充nan值。
>>> series.resample('30S').bfill()[0:5] 2000-01-01 00:00:00 0 2000-01-01 00:00:30 1 2000-01-01 00:01:00 1 2000-01-01 00:01:30 2 2000-01-01 00:02:00 2 Freq: 30S, dtype: int64通過apply執行一個自定義函式
>>> def custom_resampler(array_like): ... return np.sum(array_like)+5
>>> series.resample('3T').apply(custom_resampler) 2000-01-01 00:00:00 8 2000-01-01 00:03:00 17 2000-01-01 00:06:00 26 Freq: 3T, dtype: int64
相關推薦
Pandas中resample方法詳解
Pandas中的resample,重新取樣,是對原樣本重新處理的一個方法,是一個對常規時間序列資料重新取樣和頻率轉換的便捷的方法。 方法的格式是: DataFrame.resample(rule, h
JavaScript中getBoundingClientRect()方法詳解
script otto java chrome 頁面 支持 urn client fire getBoundingClientRect() 這個方法返回一個矩形對象,包含四個屬性:left、top、right和bottom。分別表示元素各邊與頁面上邊和左邊的距離。
boost庫中sleep方法詳解
seconds boost庫 color sys 在線 TP 方法 轉載 details 博客轉載自:https://blog.csdn.net/huang_xw/article/details/8453506 boost庫中sleep有兩個方法: 1. 這個方法只能在線程
JS中陣列方法詳解
JS中陣列的方法有很多,但是自己一直沒有抽時間進行整理分類,故單獨寫一篇博文,對目前我所掌握的JS中陣列相關的方法進行整理,夯實一下自己的基礎。 我將陣列相關的方法分為兩類 1.方法會改變原陣列 相應的方法有:shift、unshift、pop、push、rev
Java 的String中intern方法詳解及測試樣例
intern public String intern() 返回字串物件的規範化表示形式。 一個初始時為空的字串池,它由類 String 私有地維護。 當呼叫 intern 方法時,如果池已經包含一個等於此 String 物件的字串(該物件由 equals(Obj
python中list方法詳解說明
序號 分類 關鍵字/函式/方法 描述 1 新增 list.insert(索引,資料) 在指定位置插入資料 list.append(資料)
java中compareTo方法詳解
Compares two strings lexicographically. The comparison is based on the Unicode value of each character in the strings. The character sequence represented
Spring4.0MVC學習資料,ApplicationContext中的方法詳解(三)
做為java開源的一部分,spring框架一直排在老大的位置。Spring4.0 是 Spring 推出的一個重大版本升級,進一步加強了 Spring 作為 Java 領域第一開源平臺的地位。Spring4.0 引入了眾多 Java 開發者期盼的新特性,如泛型依賴注入、Sp
python中new方法詳解。
new_ 方法是什麼? __new__方法其實就是建立物件的方法 new()方法是在類準備將自身例項化時呼叫。 一個類可以有多個位置引數和多個命名引數,而在例項化開始之後,在呼叫 init()方法之前,Python首先呼叫new()方法: def new(cls, *args, **kw
PHP迴圈二維陣列 。php中__autoload()方法詳解
PHP迴圈二維陣列 PHP程式碼: <?php $arr1=array(100,200,300,400); $arr2=array("num"=>100,"name"=>"Liuxy","score"=>98); print_r($arr1); e
javascript中call方法詳解
轉載自http://www.cnblogs.com/sweting/archive/2009/12/21/1629204.html 應用於:Function 物件 要求 版本 5.5 呼叫一個物件的一個方法,以另一個物件替換當前物件。 call([thisObj[,arg1[, arg2[, [,.
js中getBoundingClientRect()方法詳解
getBoundingClientRect獲取元素位置 getBoundingClientRect用於獲得頁面中某個元素的左,上,右和下分別相對瀏覽器視窗的位置。 getBoundingClientRect是DOM元素到瀏覽器可視範圍的距離(不包含文檔卷起
集合中Collection方法詳解
有一個Cell類,程式碼如下: public class Cell implements Comparable<Cell>{ public int x; public int y;
JAVA中clone方法詳解
為了理解java的clone,有必要先了解一些東西。java的型別,java的型別分為兩大類,一類為primitive,如int,另一類為引用型別,如String,Object等等。java引用型別的儲存,java的引用型別都是儲存在堆上的。 Java程式碼 public
jquery中ajax方法詳解
1.url:要求為String型別的引數,傳送請求的地址(預設是當前網頁地址)2.type:String型別的引數,請求方式(post或get,預設為get)。請注意其他http的請求方法。3.timeout:Number型別的引數,設定請求超過時間(ms)。此設定將覆蓋$.
HTML中javascript的<script>標簽使用方法詳解
mime類型 jsp source 方式 clas 處理 網頁 鏈接 屬性。 原文地址:HTML中javascript的<script>標簽使用方法詳解 只要一提到把JavaScript放到網頁中,就不得不涉及Web的核心語言——HTML。在當初開發javasc
php中二維數組排序問題方法詳解
ges cti cmp each ace esc 對數 x11 用法 PHP中二維數組排序,可以使用PHP內置函數uasort() 示例一: 使用用戶自定義的比較函數對數組中的值進行排序並保持索引關聯 回調函數如下:註意回調函數的返回值是負數或者是false的時候,表
JS中的call、apply、bind方法詳解
面試 glob ble ole 內部 修改 sta illegal 解決 bind 是返回對應函數,便於稍後調用;apply 、call 則是立即調用 。 apply、call 在 javascript 中,call 和 apply 都是為了改變某個函數運行時的上下文(
Java中的main()方法詳解
普通 什麽 javac 無限 reflect ase 理解 jvm cep 在Java中,main()方法是Java應用程序的入口方法,也就是說,程序在運行的時候,第一個執行的方法就是main()方法,這個方法和其他的方法有很大的不同,比如方法的名字必須是main,方法必須
(轉)shell中test命令方法詳解
目的 判斷字符串 演示 警告 gic 一個數 平臺 oracl 差異 test命令用法。功能:檢查文件和比較值 原文:https://www.cnblogs.com/guanyf/p/7553940.html 1)判斷表達式 if test (表達式為真)