[英]fast pytables pandas data slicing
我的運行速度很慢。 我的數據是
<class 'pandas.io.pytables.HDFStore'>
File path: c:/data/bed_1/acc_ohlc.hdf
/000020 frame (shape->[7721,5])
/000030 frame (shape->[1037,5])
/000040 frame (shape->[7723,5])
/000050 frame (shape->[7723,5])
/000060 frame (shape->[7723,5])
/000070 frame (shape->[7724,5])
/000080 frame (shape->[2426,5])
每個都是 pandas 數據幀,每個數據長度不同。 索引是時間戳。 用於制作具有所有相同時期數據的新數據集。
begin = '20140117'
end = '20150116'
p_data = {}
for index, row in code_list.iterrows():
code = row['Code'][:-3]
p_data[code] = store[code].ix[begin:end].astype (float)
new_data = pd.Panel(p_data)
new_data = pd.Panel (p_data)
總運行時間約為 25 秒。 有什么好的代碼可以縮短運行時間嗎?
這樣的事情可能會大大加快這個過程。 .iterrows 可能不是最好的選擇。
def fun(c):
code = c[:-3]
p_data[code] = store[code].ix[begin:end].astype (float)
code_list.Code.apply(fun)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.