__getitem__(self,
key)
(Indexing operator)
Returns a column row, column slice or a sub-column.
It takes different actions depending on the type of the ``key
parameter:
If key is an integer, the corresponding column is returned as
a Record or NestedRecord object, whatever is most
appropriate. If key is a slice, the row slice determined by
key is returned as a RecArray or NestedRecArray object,
whatever is most appropriate.
Finally, if key is a string, it is interpreted as a column
name in the table, and, if it is a plain field (i.e. has not a
nested structure), a Column object is returned. If key has
a nested structure (nested column), it returns another Cols
object that can be used as a container for accessing its nested
columns. If key has a '/' character on it, this is
interpreted as a separator for nested fields (see examples).
Get table row #0:
>>> table.cols[0] # equivalent to table[0]
array(
[(1, (0.5, 1.0), ('a1', 1j))],
formats=['Int64', '(2,)Float32', ['a2', 'Complex64']],
shape=1,
names=['id', 'pos', ('info', ['name', 'value'])])
Get a non-nested column:
>>> id = table.cols['id']
Cols(table.cols.id)
>>> id[:]
array([1, 2], type=Int64)
Get a nested column:
>>> info = table.cols['info']
Cols(table.cols.info)
>>> info[:]
array(
[('a1', 1j),
('a2', 1+.1j)],
formats=['a2', 'Complex64'],
shape=2,
names=['info', ['name', 'value']])
Get a deeply nested column (using a mix of natural naming and getitem):
>>> value = table.cols.info['value']
Column(table.cols.info.value) # Note that this is plain Column!
>>> value[1]
(1+0.10000000000000001j)
>>> value[:]
array([ 0.+1.j , 1.+0.1j])
-
|