hstack¶
- astropy.table.hstack(tables, join_type='outer', uniq_col_name='{col_name}_{table_name}', table_names=None, metadata_conflicts='warn')[source]¶
Stack tables along columns (horizontally)
A
join_type
of ‘exact’ means that the tables must all have exactly the same number of rows. Ifjoin_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
Table
orRow
orpython:list
thereof Tables to stack along columns (horizontally) with the current table
- join_type
python:str
Join type (‘inner’ | ‘exact’ | ‘outer’), default is ‘outer’
- uniq_col_name
python:str
orpython:None
String generate a unique output column name in case of a conflict. The default is ‘{col_name}_{table_name}’.
- table_names
python:list
ofpython:str
orpython:None
Two-element list of table names used when generating unique output column names. The default is [‘1’, ‘2’, ..].
- metadata_conflicts
python: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.
- tables
- Returns:
- stacked_table
Table
object
New table containing the stacked data from the input tables.
- stacked_table
See also
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