开发者

What is the most elegant way of selecting a subset of columns using pytables?

I have a dataset with 300+ columns in pytables, and I want to be able to choose different subsets easily. There doesn't seem to be a very elegant solution to this, or is there something I'm missing?

I would also be happy with a way to create another table that is simply aliasing select columns from the original table, so that I could have my main table and then my subset teables. 开发者_运维问答Is there a way to do that?


Would something like this work?

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)

gives,

(array([1, 5, 9, 3, 2]), array([4, 1, 8, 2, 6]))
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜