A class to represent tables of heterogeneous data.
Table provides a class for heterogeneous tabular data, making use of a numpy structured array internally to store the data values. A key enhancement provided by the Table class is the ability to easily modify the structure of the table by adding or removing columns, or adding new rows of data. In addition table and column metadata are fully supported.
Table differs from NDData by the assumption that the input data consists of columns of homogeneous data, where each column has a unique identifier and may contain additional metadata such as the data units, format, and description.
| Parameters : | data : numpy ndarray, dict, list, or Table, optional
names : list, optional
dtypes : list, optional
meta : dict, optional
copy : boolean, optional
|
|---|
Add a new Column object col to the table. If index is supplied then insert column before index position in the list of columns, otherwise append column to the end of the list.
| Parameters : | col : Column
index : int or None
|
|---|
Add a list of new Column objects cols to the table. If a corresponding list of indexes is supplied then insert column before each index position in the original list of columns, otherwise append columns to the end of the list.
| Parameters : | cols : list of Columns
indexes : list of ints or None
|
|---|
Add a new row to the end of the table.
The vals argument can be:
This method requires that the Table object “owns” the underlying array data. In particular one cannot add a row to a Table that was initialized with copy=False from an existing array.
| Parameters : | vals : tuple, list, dict or None
|
|---|
Return column[item] for recarray compatibility.
Return the positional index of column name.
| Parameters : | name : str
|
|---|---|
| Returns : | index : int
|
Keep only the columns specified (remove the others)
| Parameters : | names : list
|
|---|
Python 3 iterator
Remove a column from the table.
This can also be done with:
del table[name]
| Parameters : | name : str
|
|---|
Remove several columns from the table
| Parameters : | names : list
|
|---|
Rename a column.
This can also be done directly with by setting the name attribute for a column:
table[name].name = new_name
| Parameters : | name : str
new_name : str
|
|---|
Reverse the row order of table rows. The table is reversed in place and there are no function arguments.
Sort the table according to one or more keys. This operates on the existing table and does not return a new table.
| Parameters : | keys : str or list of str
|
|---|
Define a data column for use in a Table object.
| Parameters : | name : str
data : list, ndarray or None
dtype : numpy.dtype compatible value
shape : tuple or ()
length : int or 0
description : str or None
units : str or None
format : str or None
meta : dict-like or None
|
|---|
Examples
A Column can be created in two different ways:
Provide a data value and optionally a dtype value
Examples:
col = Column('name', data=[1, 2, 3]) # shape=(3,)
col = Column('name', data=[[1, 2], [3, 4]]) # shape=(2, 2)
col = Column('name', data=[1, 2, 3], dtype=float)
col = Column('name', np.array([1, 2, 3]))
col = Column('name', ['hello', 'world'])
The dtype argument can be any value which is an acceptable fixed-size data-type initializer for the numpy.dtype() method. See http://docs.scipy.org/doc/numpy/reference/arrays.dtypes.html. Examples include:
If no dtype value is provide then the type is inferred using np.array(data). When data is provided then the shape and length arguments are ignored.
Provide zero or more of dtype, shape, length
Examples:
col = Column('name')
col = Column('name', dtype=int, length=10, shape=(3,4))
The default dtype is np.float64 and the default length is zero. The shape argument is the array shape of a single cell in the column. The default shape is () which means a single value in each element.
Compare the column attributes of col to this object.
The comparison attributes are: name, units, dtype, format, description, and meta.
| Parameters : | col: Column :
|
|---|---|
| Returns : | equal: boolean :
|
Return a copy of the current Column instance.
Array-interface compliant full description of the column.
This returns a 3-tuple (name, type, shape) that can always be used in a structured array dtype definition.
A class to represent one row of a Table object.
A Row object is returned when a Table object is indexed with an integer or when iterating over a table:
>>> table = Table([(1, 2), (3, 4)], names=('a', 'b'))
>>> row = table[1]
>>> row
<Row 1 of table
values=(2, 4)
dtype=[('a', '<i8'), ('b', '<i8')]>
>>> row['a']
2
>>> row[1]
4
OrderedDict subclass for a set of columns.
This class enhances item access to provide convenient access to columns by name or index, including slice access. It also handles renaming of columns.
The initialization argument cols can be any structure that is valid for initializing a Python dict. This includes a dict, list of (key, val) tuple pairs, list of [key, val] lists, etc.
| Parameters : | cols : dict, list, tuple; optional
|
|---|