Column

class astropy.table.table.Column[source] [edit on github]

Bases: astropy.table.table.BaseColumn, numpy.ndarray

Define a data column for use in a Table object.

Parameters :

name : str

Column name and key for reference within Table

data : list, ndarray or None

Column data values

dtype : numpy.dtype compatible value

Data type for column

shape : tuple or ()

Dimensions of a single row element in the column data

length : int or 0

Number of row elements in column data

description : str or None

Full description of column

units : str or None

Physical units

format : str or None

Format string for outputting column values. This can be an “old-style” (format % value) or “new-style” (str.format) format specification string.

meta : dict-like or None

Meta-data associated with the column

Examples

A Column can be created in two different ways:

  • Provide a data value but not shape or length (which are inferred from the data).

    Examples:

    col = Column(data=[1, 2], name='name')  # shape=(2,)
    col = Column(data=[[1, 2], [3, 4]], name='name')  # shape=(2, 2)
    col = Column(data=[1, 2], name='name', dtype=float)
    col = Column(data=np.array([1, 2]), name='name')
    col = Column(data=['hello', 'world'], name='name')
    

    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:

    • Python non-string type (float, int, bool)
    • Numpy non-string type (e.g. np.float32, np.int64, np.bool)
    • Numpy.dtype array-protocol type strings (e.g. ‘i4’, ‘f8’, ‘S15’)

    If no dtype value is provide then the type is inferred using np.array(data).

  • Provide length and optionally shape, but not data

    Examples:

    col = Column(name='name', length=5)
    col = Column(name='name', dtype=int, length=10, shape=(3,4))
    

    The default dtype is np.float64. The shape argument is the array shape of a single cell in the column.

Warning

In the next major release of astropy (0.3), the order of function arguments for creating a Column will change. Currently the order is Column(name, data, ...), but in 0.3 and later it will be Column(data, name, ...). This improves consistency with Table and numpy.

In order to use the same code for Astropy 0.2 and 0.3, column objects should always be created using named keyword arguments for data and name, for instance c = Column(data=[1, 2], name='col'). When Astropy 0.3 is released then the the keyword identifiers can be dropped, allowing for c = Column([1, 2], 'c').

Attributes Summary

data

Methods Summary

copy([data, copy_data]) Return a copy of the current Column instance.

Attributes Documentation

data[source]

Methods Documentation

copy(data=None, copy_data=True)[source] [edit on github]

Return a copy of the current Column instance. If data is supplied then a view (reference) of data is used, and copy_data is ignored.

Page Contents