tables_io.utils.concat_utils
Concatenation functions for tables_io
Functions
|
Vertically concatenates a sequence of Table-like objects. The concatenation |
|
Vertically concatenates a list of TableDict-like objects. Each Table-like object |
|
Concatenate a list of astropy.table.Table |
|
Concatenate a list of dicts of np.array objects |
|
Concatenate a list of dicts of np.recarray objects |
|
Concatenate a list of pandas.DataFrame |
|
Concatenate a list of pyarrow.Table objects |
Module Contents
- concat_table(tableList: List, tType: str | int)[source]
Vertically concatenates a sequence of Table-like objects. The concatenation is performed as an outer join, where no data is lost.
Note: When concatenating NUMPY_RECARRAY objects, the output arrays will be masked arrays if any fill values are required by the concatenation.
Accepted table formats:
Format string
Format integer
“astropyTable”
0
“numpyDict”
1
“numpyRecarray”
2
“pandasDataFrame”
3
“pyarrowTable”
4
- Parameters:
tablelist (list) – The list of tables
tType (str or int) – The tabular format of the tables given.
- Returns:
tab – The concatenated table
- Return type:
Table-like
Example
>>> import tables_io >>> import pandas as pd >>> df = pd.DataFrame({'col_1': [1,2,3], 'col_2':[3,4,5]}) >>> df_2 = pd.DataFrame({'col_2': [8,9], 'col_3': [10,11]}) >>> tables_io.concat_table([df,df_2],'pandasDataFrame') col_1 col_2 col_3 0 1.0 3 NaN 1 2.0 4 NaN 2 3.0 5 NaN 3 NaN 8 10.0 4 NaN 9 11.0
- concat_tabledict(odictlist: List[Mapping], tType: str | int) Mapping[source]
Vertically concatenates a list of TableDict-like objects. Each Table-like object in a TableDict-like object will be concatenated with any matching Table-like objects in the other TableDict-like objects (where matching means they have the same key). The final TableDict-like object will contain all unique Table-like objects (those with unique keys).
The concatenation will be of join type outer, which means that no data will be lost.
Note: If concatenating NUMPY_RECARRAY objects, the output arrays will be masked arrays if any fill values are required by the concatenation.
- Parameters:
odictlist (list of ‘TableDict-like’) – The input objects
tType (str or int) – The tabular format of the tables given.
- Returns:
tabs – A TableDict-like object of the concatenated Table-like objects
- Return type:
OrderedDict of Table-like
Example
>>> import tables_io >>> from astropy.table import Table >>> odict_1 = OrderedDict([('tab_1', Table([[1.5,2.2],[5,3]],names=("x","y"))), ... ('tab_2', Table([[1,2.4,4],[5,3,7]],names=("x","y")))]) >>> odict_2 = OrderedDict([('tab_1', Table([[5.2,7.6],[14,20],[8,16]],names=("x","y","z"))), ... ('tab_2', Table([[8,9.1,3],[1,4,8]],names=("x","y")))]) >>> tables_io.concat([odict1, odict_2], ') OrderedDict([('tab_1', <Table length=4> x y z float64 int64 int64 ------- ----- ----- 1.5 5 -- 2.2 3 -- 5.2 14 8 7.6 20 16), ('tab_2', <Table length=6> x y float64 int64 ------- ----- 1.0 5 2.4 3 4.0 7 8.0 1 9.1 4 3.0 8)])
- concat_ap_tables(tablelist: List)[source]
Concatenate a list of astropy.table.Table
- Parameters:
tablelist (list) – The list of tables
- Returns:
tab – The concatenated table
- Return type:
astropy.table.Table
- concat_numpy_dicts(tablelist: List)[source]
Concatenate a list of dicts of np.array objects
- Parameters:
tablelist (list) – The list of tables
- Returns:
tab – The concatenated table
- Return type:
dict
- concat_numpy_recarrays(tablelist: List)[source]
Concatenate a list of dicts of np.recarray objects
- Parameters:
tablelist (list) – The list of tables
- Returns:
tab – The table
- Return type:
dict