开发者

PyTable Column Order

Is there a way to create a PyTable with a specific column ord开发者_如何学Cer?

By default, the columns are alphabetically ordered when using both dictionary or class for schema definition for the call to createTable(). My need is to establish a specific order and then use numpy.genfromtxt() to read and store my data from text. Unfortunately, my text file does not have the variable names included in the same way that the file data is.

At this time, my column are ordered alphabetically and the data is misaligned in that it is ordered according to the file layout. And it is desirable to maintain the same order in the pyTable (but, not essential).

Thanks


See:

Is there a way to store PyTable columns in a specific order?


For example, assuming text file is named mydata.txt and is organized as follows:

time(row1) bVar(row1) dVar(row1) aVar(row1) cVar(row1)

time(row2) bVar(row2) dVar(row2) aVar(row2) cVar(row2) ...

time(rowN) bVar(rowN) dVar(rowN) aVar(rowN) cVar(rowN)

So, the desire is to create a table that is ordered with these columns and then use the numpy.genfromtxt command to populate the table.

# Column and Table definition with desired order
class parmDev(tables.IsDescription):
    time = tables.Float64Col()
    bVar = tables.Float64Col()
    dVar = tables.Float64Col()
    aVar = tables.Float64Col()
    cVar = tables.Float64Col()

#...

mytab = tables.createTable( group, tabName, paramDev )

data = numpy.genfromtxt(mydata.txt)
mytab.append(data)

This makes for straightforward code and is very fast. But, the table columns are always ordered alphabetically and the appended data is ordered according to the desired order. Is there a way to have the order of the table columns follow the class definition order instead of being alphabetical.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜