Skip to content

Commit d2d0f0a

Browse files
committed
Add Table.concatenate(...)
1 parent 5699d31 commit d2d0f0a

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

xdeps/table.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -753,6 +753,21 @@ def from_pandas(cls, df, index=None, lowercase=False):
753753
data[cc] = dd
754754
return cls(data, col_names=col_names, index=index)
755755

756+
@classmethod
757+
def concatenate(cls, tables):
758+
"""Concatenate a list of tables."""
759+
760+
# Use only common columns
761+
col_names = set(tables[0]._col_names)
762+
for tt in tables[1:]:
763+
col_names &= set(tt._col_names)
764+
765+
data = {}
766+
for cc in col_names:
767+
data[cc] = np.concatenate([tt[cc] for tt in tables])
768+
769+
return cls(data)
770+
756771
@classmethod
757772
def from_csv(cls, filename, index=None, **kwargs):
758773
import pandas as pd

0 commit comments

Comments
 (0)