PyTables User's Guide: Hierarchical datasets in Python - Release 1.3.2 | ||
---|---|---|
Prev | Chapter 4. Library Reference | Next |
Each instance of this class is associated with one column of every table. These instances are mainly used to fetch and set actual data from the table columns, but there are a few other associated methods to deal with indexes.
The parent Table instance.
The name of the associated column.
The complete pathname of the associated column. This is mainly useful in nested columns; for non-nested ones this value is the same a name.
The data type of the column.
The shape of the column.
The associated Index object (see 4.17.3) to this column (None if does not exist).
Whether the index is dirty or not (property).
Recompute the index associated with this column. This can be useful when you suspect that, for any reason, the index information is no longer valid and want to rebuild it.
Recompute the existing index only if it is dirty. This can be useful when you have set the reindex parameter to 0 in IndexProps constructor (see 4.17.2) for the table and want to update the column's index after a invalidating index operation (Table.removeRows, for example).
Delete the associated column's index. After doing that, you will loose the indexation information on disk. However, you can always re-create it using the createIndex() method (see 4.9.2).
Returns a column element or slice. It takes different actions depending on the type of the key parameter:
The corresponding element in the column is returned as a scalar object or as a numarray object, depending on its shape.
The row range determined by this slice is returned as a numarray object.
Example of use:
print "Column handlers:" for name in table.colnames: print table.cols[name] print print "Some selections:" print "Select table.cols.name[1]-->", table.cols.name[1] print "Select table.cols.name[1:2]-->", table.cols.name[1:2] print "Select table.cols.lati[1:3]-->", table.cols.lati[1:3] print "Select table.cols.pressure[:]-->", table.cols.pressure[:] print "Select table.cols['temperature'][:]-->", table.cols['temperature'][:]and the output of this for a certain arbitrary table is:
Column handlers: /table.cols.name (Column(1,), CharType) /table.cols.lati (Column(2,), Int32) /table.cols.longi (Column(1,), Int32) /table.cols.pressure (Column(1,), Float32) /table.cols.temperature (Column(1,), Float64) Some selections: Select table.cols.name[1]--> Particle: 11 Select table.cols.name[1:2]--> ['Particle: 11'] Select table.cols.lati[1:3]--> [[11 12] [12 13]] Select table.cols.pressure[:]--> [ 90. 110. 132.] Select table.cols['temperature'][:]--> [ 100. 121. 144.]See the examples/table2.py for a more complete example.
It takes different actions depending on the type of the key parameter:
The corresponding element in the column is set to value. value must be a scalar or numarray/NumPy object, depending on column's shape.
The row slice determined by key is set to value. value must be a list of elements or a numarray/NumPy.
Example of use:
# Modify row 1 table.cols.col1[1] = -1 # Modify rows 1 and 3 table.cols.col1[1::2] = [2,3]
Which is equivalent to:
# Modify row 1 table.modifyColumns(start=1, columns=[[-1]], names=["col1"]) # Modify rows 1 and 3 columns = numarray.records.fromarrays([[2,3]], formats="i4") table.modifyColumns(start=1, step=2, columns=columns, names=["col1"])