The PyTable columns seem to be sorted alphabetically when using a dictionary or class to define the schema for calling createTable (). I need to set a specific order and then use numpy.genfromtxt () to read and store my data from text. My text file does not have variable names included in alphabetical order, as for PyTable.
For example, if the text file is named mydata.txt and is organized as follows:
time (line1) bVar (line1) dVar (line1) aVar (line1) cVar (line1)
time (line2) bVar (line2) dVar (line2) aVar (line2) cVar (line2) ...
time (line N) bVar (line N) dVar (line N) aVar (line N) cVar (line N)
So, desire to create a table ordered with these columns and then use the numpy.genfromtxt command to populate the table.
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 is desirable because it is simple code and very fast. But PyTable columns are always sorted alphabetically, and the attached data is sorted in the order you want. Am I losing something here? Is there a way for the column order of the table to follow the order in which the class is defined, rather than alphabetically?
source
share