datascience.tables.Table.join

Table.join(column_label, other, other_label=None)[source]

Creates a new table with the columns of self and other, containing rows for all values of a column that appear in both tables.

Args:
column_label: label of column or array of labels in self that is used to

join rows of other.

other: Table object to join with self on matching values of

column_label.

Kwargs:
other_label: default None, assumes column_label.

Otherwise in other used to join rows.

Returns:

New table self joined with other by matching values in column_label and other_label. If the resulting join is empty, returns None.

>>> table = Table().with_columns('a', make_array(9, 3, 3, 1),
...     'b', make_array(1, 2, 2, 10),
...     'c', make_array(3, 4, 5, 6))
>>> table
a    | b    | c
9    | 1    | 3
3    | 2    | 4
3    | 2    | 5
1    | 10   | 6
>>> table2 = Table().with_columns( 'a', make_array(9, 1, 1, 1),
... 'd', make_array(1, 2, 2, 10),
... 'e', make_array(3, 4, 5, 6))
>>> table2
a    | d    | e
9    | 1    | 3
1    | 2    | 4
1    | 2    | 5
1    | 10   | 6
>>> table.join('a', table2)
a    | b    | c    | d    | e
1    | 10   | 6    | 2    | 4
1    | 10   | 6    | 2    | 5
1    | 10   | 6    | 10   | 6
9    | 1    | 3    | 1    | 3
>>> table.join('a', table2, 'a') # Equivalent to previous join
a    | b    | c    | d    | e
1    | 10   | 6    | 2    | 4
1    | 10   | 6    | 2    | 5
1    | 10   | 6    | 10   | 6
9    | 1    | 3    | 1    | 3
>>> table.join('a', table2, 'd') # Repeat column labels relabeled
a    | b    | c    | a_2  | e
1    | 10   | 6    | 9    | 3
>>> table2 #table2 has three rows with a = 1
a    | d    | e
9    | 1    | 3
1    | 2    | 4
1    | 2    | 5
1    | 10   | 6
>>> table #table has only one row with a = 1
a    | b    | c
9    | 1    | 3
3    | 2    | 4
3    | 2    | 5
1    | 10   | 6
>>> table.join(['a', 'b'], table2, ['a', 'd']) # joining on multiple columns
a    | b    | c    | e
1    | 10   | 6    | 6
9    | 1    | 3    | 3