astro py:docs

- Index
- Modules

### Navigation

- next »
- « previous |
- Astropy v1.1.1 »
- Data Tables (`astropy.table`) »
- hstack

# hstack

`astropy.table.``hstack`(tables, join_type=u'outer', uniq_col_name=u'{col_name}_{table_name}', table_names=None, metadata_conflicts=u'warn')

  Stack tables along columns (horizontally)

  A `join_type` of ‘exact’ means that the tables must all have exactly the same number of rows. If `join_type` is ‘inner’ then the intersection of rows will be the output. A value of ‘outer’ (default) means the output will have the union of all rows, with table values being masked where no common values are available.

  Parameters:

  tables : List of Table objects

  > Tables to stack along columns (horizontally) with the current table

  join_type : str

  > Join type (‘inner’ | ‘exact’ | ‘outer’), default is ‘outer’

  uniq_col_name : str or None

  > String generate a unique output column name in case of a conflict. The default is ‘{col_name}_{table_name}’.

  table_names : list of str or None

  > Two-element list of table names used when generating unique output column names. The default is [‘1’, ‘2’, ..].

  metadata_conflicts : str

  > How to proceed with metadata conflicts. This should be one of:
  >   - `'silent'`: silently pick the last conflicting meta-data value
  >   - `'warn'`: pick the last conflicting meta-data value, but emit a warning (default)
  >   - `'error'`: raise an exception.

  Returns:

  stacked_table : `Table` object

  > New table containing the stacked data from the input tables.

  Examples

  To stack two tables horizontally (along columns) do:

      >>> from astropy.table import Table, hstack
      >>> t1 = Table({'a': [1, 2], 'b': [3, 4]}, names=('a', 'b'))
      >>> t2 = Table({'c': [5, 6], 'd': [7, 8]}, names=('c', 'd'))
      >>> print(t1)
       a   b
      --- ---
        1   3
        2   4
      >>> print(t2)
       c   d
      --- ---
        5   7
        6   8
      >>> print(hstack([t1, t2]))
       a   b   c   d
      --- --- --- ---
        1   3   5   7
        2   4   6   8