setdiff¶
-
astropy.table.setdiff(table1, table2, keys=None)[source] [edit on github]¶ Take a set difference of table rows.
The row set difference will contain all rows in
table1that are not present intable2. If the keys parameter is not defined, all columns intable1will be included in the output table.Parameters: table1 :
Tabletable1is on the left side of the set difference.table2 :
Tabletable2is on the right side of the set difference.keys : str or list of str
Name(s) of column(s) used to match rows of left and right tables. Default is to use all columns in
table1.Returns: diff_table :
TableNew table containing the set difference between tables. If the set difference is none, an empty table will be returned.
Examples
To get a set difference between two tables:
>>> from astropy.table import setdiff, Table >>> t1 = Table({'a': [1, 4, 9], 'b': ['c', 'd', 'f']}, names=('a', 'b')) >>> t2 = Table({'a': [1, 5, 9], 'b': ['c', 'b', 'f']}, names=('a', 'b')) >>> print(t1) a b --- --- 1 c 4 d 9 f >>> print(t2) a b --- --- 1 c 5 b 9 f >>> print(setdiff(t1, t2)) a b --- --- 4 d >>> print(setdiff(t2, t1)) a b --- --- 5 b