use*_*736 2 python hdf5 pytables
我在pytables中有一个包含300多列的数据集,我希望能够轻松选择不同的子集.似乎没有一个非常优雅的解决方案,或者有什么我想念的?
我也很高兴有一种方法可以创建另一个表,它简单地对原始表中的选择列进行别名,这样我就可以拥有我的主表,然后是我的子集teables.有没有办法做到这一点?
会这样的吗?
from numpy import array, dtype
from h5py import File
from operator import itemgetter
# Dummy data
d = dtype([('a', int),('b', int),('c', int)])
a = array([(1, 6, 4), (5, 7, 1), (9, 7, 8), (3, 1, 2), (2, 1, 6)],dtype=d)
hdf = File('tmp.hdf','a')
hdf.create_dataset('data',data=a)
hdf.flush()
# Extract data
dat = hdf.get('data',default=0)
sub = ['a','c']
get = itemgetter(*sub)
print get(dat)
Run Code Online (Sandbox Code Playgroud)
给,
(array([1, 5, 9, 3, 2]), array([4, 1, 8, 2, 6]))
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1527 次 |
| 最近记录: |