【发布时间】:2014-09-13 11:42:59
【问题描述】:
我们以以下为例:
import tables
import numpy as np
# Two Example Tables
hfile = tables.open_file('myfile.h5', 'a')
data1 = np.ones((3, 2))
data1.dtype = [('a', float), ('b', float)]
data2 = np.zeros((3, 2))
data2.dtype = [('a', float), ('b', float)]
table1 = hfile.create_table(where='/', name='table1', obj=data1)
table2 = hfile.create_table(where='/', name='table2', obj=data2)
# Appending
table1.append(table2.read())
table2.remove()
hfile.flush()
hfile.close()
有没有更好的方法在磁盘上执行此操作?
一种解决方案是遍历行:
for r in table2.iterrows():
table1.append([r[:]])
后者似乎很庞大,而前者在追加之前将整个第二个表绘制到内存中。我宁愿做这样的事情:
table2.append_where(dstTable=table1)
但是这个函数只适用于一个条件,所以我需要一个总是评估为真的函数来获取整个表。肯定有更好的办法。
【问题讨论】:
标签: python database hdf5 pytables