Table Of Contents

Previous topic

Online queries

Next topic

Full API for TableSet class

This Page

Full API for Table class

Table initialization and I/O

Table.reset()

Empty the table

Table.read(*args, **kwargs)

Read in a table from a file/database.

Optional Keyword Arguments (independent of table type):

verbose: [ True | False ]
Whether to print out warnings when reading (default is True)
type: [ string ]
The read method attempts to automatically guess the file/database format based on the arguments supplied. The type can be overridden by setting this argument.
Table.write(*args, **kwargs)

Write out a table to a file/database.

Optional Keyword Arguments (independent of table type):

verbose: [ True | False ]
Whether to print out warnings when writing (default is True)
type: [ string ]
The read method attempts to automatically guess the file/database format based on the arguments supplied. The type can be overridden by setting this argument.

Meta-data

Table.add_comment(comment)

Add a comment to the table

Required Argument:

comment: [ string ]
The comment to add to the table
Table.add_keyword(key, value)

Add a keyword/value pair to the table

Required Arguments:

key: [ string ]
The name of the keyword
value: [ string | float | integer | bool ]
The value of the keyword
Table.describe()

Prints a description of the table

Column manipulation

Table.add_column(name, data, unit='', null='', description='', format=None, dtype=None, column_header=None, before=None, after=None, position=None, mask=None, fill=None)

Add a column to the table

Required Arguments:

name: [ string ]
The name of the column to add
data: [ numpy array ]
The column data

Optional Keyword Arguments:

unit: [ string ]
The unit of the values in the column
null: [ same type as data ]
The values corresponding to ‘null’, if not NaN
description: [ string ]
A description of the content of the column
format: [ string ]
The format to use for ASCII printing
dtype: [ numpy type ]
Numpy type to convert the data to. This is the equivalent to the dtype= argument in numpy.array
column_header: [ ColumnHeader ]

The metadata from an existing column to copy over. Metadata includes the unit, null value, description, format, and dtype. For example, to create a column ‘b’ with identical metadata to column ‘a’ in table ‘t’, use:

>>> t.add_column('b', column_header=t.columns[a])
before: [ string ]
Column before which the new column should be inserted
after: [ string ]
Column after which the new column should be inserted
position: [ integer ]
Position at which the new column should be inserted (0 = first column)
mask: [ numpy array ]
An array of booleans, with the same dimensions as the data, indicating whether or not to mask values.
fill: [ value ]
If masked arrays are used, this value is used as the fill value in the numpy masked array.
Table.add_empty_column(name, dtype, unit='', null='', description='', format=None, column_header=None, shape=None, before=None, after=None, position=None)

Add an empty column to the table. This only works if there are already existing columns in the table.

Required Arguments:

name: [ string ]
The name of the column to add
dtype: [ numpy type ]
Numpy type of the column. This is the equivalent to the dtype= argument in numpy.array

Optional Keyword Arguments:

unit: [ string ]
The unit of the values in the column
null: [ same type as data ]
The values corresponding to ‘null’, if not NaN
description: [ string ]
A description of the content of the column
format: [ string ]
The format to use for ASCII printing
column_header: [ ColumnHeader ]

The metadata from an existing column to copy over. Metadata includes the unit, null value, description, format, and dtype. For example, to create a column ‘b’ with identical metadata to column ‘a’ in table ‘t’, use:

>>> t.add_column('b', column_header=t.columns[a])
shape: [ tuple ]
Tuple describing the shape of the empty column that is to be added. If a one element tuple is specified, it is the number of rows. If a two element tuple is specified, the first is the number of rows, and the second is the width of the column.
before: [ string ]
Column before which the new column should be inserted
after: [ string ]
Column after which the new column should be inserted
position: [ integer ]
Position at which the new column should be inserted (0 = first column)
Table.remove_columns(remove_names)

Remove several columns from the table

Required Argument:

remove_names: [ list of strings ]
A list containing the names of the columns to remove
Table.keep_columns(keep_names)

Keep only specific columns in the table (remove the others)

Required Argument:

keep_names: [ list of strings ]
A list containing the names of the columns to keep. All other columns will be removed.
Table.rename_column(old_name, new_name)

Rename a column from the table

Require Arguments:

old_name: [ string ]
The current name of the column.
new_name: [ string ]
The new name for the column
Table.set_primary_key(key)

Set the name of the table column that should be used as a unique identifier for the record. This is the same as primary keys in SQL databases. A primary column cannot contain NULLs and must contain only unique quantities.

Required Arguments:

key: [ string ]
The column to use as a primary key

Table manipulation and selection

Table.sort(keys)

Sort the table according to one or more keys. This operates on the existing table (and does not return a new table).

Required arguments:

keys: [ string | list of strings ]
The key(s) to order by
Table.row(row_number, python_types=False)

Returns a single row

Required arguments:

row_number: [ integer ]
The row number (the first row is 0)

Optional Keyword Arguments:

python_types: [ True | False ]
Whether to return the row elements with python (True) or numpy (False) types.
Table.rows(row_ids)

Select specific rows from the table and return a new table instance

Required Argument:

row_ids: [ list | np.int array ]
A python list or numpy array specifying which rows to select, and in what order.

Returns:

A new table instance, containing only the rows selected
Table.where(mask)

Select matching rows from the table and return a new table instance

Required Argument:

mask: [ np.bool array ]
A boolean array with the same length as the table.

Returns:

A new table instance, containing only the rows selected