astropy:docs

Column

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

Bases: astropy.table.column.BaseColumn

Define a data column for use in a Table object.

Parameters:

data : list, ndarray or None

Column data values

name : str

Column name and key for reference within Table

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

unit : str or None

Physical unit

format : str or None or function or callable

Format string for outputting column values. This can be an “old-style” (format % value) or “new-style” (str.format) format specification string or a function or any callable object that accepts a single value and returns a 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.

Attributes Summary

name

Methods Summary

convert_unit_to(new_unit[, equivalencies]) Converts the values of the column in-place from the current unit to the given unit.
copy([order, data, copy_data]) Return a copy of the current instance.
more([max_lines, show_name, show_unit]) Interactively browse column with a paging interface.
pformat([max_lines, show_name, show_unit]) Return a list of formatted string representation of column values.
pprint([max_lines, show_name, show_unit]) Print a formatted string representation of column values.

Attributes Documentation

name

Methods Documentation

convert_unit_to(new_unit, equivalencies=[]) [edit on github]

Converts the values of the column in-place from the current unit to the given unit.

To change the unit associated with this column without actually changing the data values, simply set the unit property.

Parameters:

new_unit : str or astropy.units.UnitBase instance

The unit to convert to.

equivalencies : list of equivalence pairs, optional

A list of equivalence pairs to try if the unit are not directly convertible. See Equivalencies.

Raises:

astropy.units.UnitsError

If units are inconsistent

copy(order=u'C', data=None, copy_data=True) [edit on github]

Return a copy of the current instance.

If data is supplied then a view (reference) of data is used, and copy_data is ignored.

Parameters:

order : {‘C’, ‘F’, ‘A’, ‘K’}, optional

Controls the memory layout of the copy. ‘C’ means C-order, ‘F’ means F-order, ‘A’ means ‘F’ if a is Fortran contiguous, ‘C’ otherwise. ‘K’ means match the layout of a as closely as possible. (Note that this function and :func:numpy.copy are very similar, but have different default values for their order= arguments.) Default is ‘C’.

data : array, optional

If supplied then use a view of data instead of the instance data. This allows copying the instance attributes and meta.

copy_data : bool, optional

Make a copy of the internal numpy array instead of using a reference. Default is True.

Returns:

col: Column or MaskedColumn

Copy of the current column (same type as original)

more(max_lines=None, show_name=True, show_unit=False) [edit on github]

Interactively browse column with a paging interface.

Supported keys:

f, <space> : forward one page
b : back one page
r : refresh same page
n : next row
p : previous row
< : go to beginning
> : go to end
q : quit browsing
h : print this help
Parameters:

max_lines : int

Maximum number of lines in table output

show_name : bool

Include a header row for column names (default=True)

show_unit : bool

Include a header row for unit (default=False)

pformat(max_lines=None, show_name=True, show_unit=False) [edit on github]

Return a list of formatted string representation of column values.

If no value of max_lines is supplied then the height of the screen terminal is used to set max_lines. If the terminal height cannot be determined then the default will be determined using the astropy.conf.max_lines configuration item. If a negative value of max_lines is supplied then there is no line limit applied.

Parameters:

max_lines : int

Maximum lines of output (header + data rows)

show_name : bool

Include column name (default=True)

show_unit : bool

Include a header row for unit (default=False)

Returns:

lines : list

List of lines with header and formatted column values

pprint(max_lines=None, show_name=True, show_unit=False) [edit on github]

Print a formatted string representation of column values.

If no value of max_lines is supplied then the height of the screen terminal is used to set max_lines. If the terminal height cannot be determined then the default will be determined using the astropy.conf.max_lines configuration item. If a negative value of max_lines is supplied then there is no line limit applied.

Parameters:

max_lines : int

Maximum number of values in output

show_name : bool

Include column name (default=True)

show_unit : bool

Include a header row for unit (default=False)

Page Contents