setdiff#

astropy.table.setdiff(table1, table2, keys=None)[source]#

Take a set difference of table rows.

The row set difference will contain all rows in table1 that are not present in table2. If the keys parameter is not defined, all columns in table1 will be included in the output table.

Parameters:
table1Table

table1 is on the left side of the set difference.

table2Table

table2 is on the right side of the set difference.

keysstr 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_tableTable

New 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