繁体   English   中英

快速 pytables pandas 数据切片

[英]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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM