2013-02-13 67 views
18

我有基於分鐘的OHLCV數據,用於打開範圍/第一個小時(9:30-10:30 AM EST)。我正在尋找重新採樣這個數據,所以我可以得到一個60分鐘的值,然後計算範圍。重採樣分鐘數據

當我調用數據的dataframe.resample()函數時,我得到兩行,最初的行從上午9:00開始。我期待着從上午9:30開始只有一排。

注意:最初的數據從9:30開始。

enter image description here

編輯:添加代碼:

# Extract data for regular trading hours (rth) from the 24 hour data set 
rth = data.between_time(start_time = '09:30:00', end_time = '16:15:00', include_end = False) 

# Extract data for extended trading hours (eth) from the 24 hour data set 
eth = data.between_time(start_time = '16:30:00', end_time = '09:30:00', include_end = False) 

# Extract data for initial balance (rth) from the 24 hour data set 
initial_balance = data.between_time(start_time = '09:30:00', end_time = '10:30:00', include_end =  False) 

卡住了試圖通過個別日期分隔開度範圍內,並獲得初始餘額

conversion = {'Open' : 'first', 'High' : 'max', 'Low' : 'min', 'Close' : 'last', 'Volume' : 'sum'} 
sample = data.between_time(start_time = '09:30:00', end_time = '10:30:00', include_end = False) 
sample = sample.ix['2007-05-07'] 
sample.tail() 

sample.resample('60Min', how = conversion) 

默認情況下重新取樣開始於小時的開始。我希望它從數據開始的地方開始。

+4

如果您複製和粘貼文本,而不是使用圖像:) – 2013-02-13 19:07:12

回答

21

可以使用base說法resample

sample.resample('60Min', how=conversion, base=30) 

the above docs-link

baseint,默認爲0
     對於均勻細分每日1次,頻率「來源「的彙總間隔。
       例如,「5分鐘」的頻率,基地的範圍可以從0到4默認爲0

+1

這對我們來說更容易感謝安迪做到了這一點。非常感激。 – aozkan 2013-02-13 19:20:25

+2

安迪,你搖滾!我浪費了很多時間去嘗試重新取樣('H',base = 30)',直到我看到你的'60Min''技巧。 – 2017-10-18 21:05:40