# biom-format.org

## biom.table.Table.merge

Table.merge(other, sample='union', observation='union', sample_metadata_f=<function prefer_self>, observation_metadata_f=<function prefer_self>)

  Merge two tables together

  The axes, samples and observations, can be controlled independently. Both can work on either “union” or “intersection”.

  sample_metadata_f and observation_metadata_f define how to merge metadata between tables. The default is to just keep the metadata associated to self if self has metadata otherwise take metadata from other. These functions are given both metadata dicts and must return a single metadata dict

  Parameters:
    other biom.Table or Iterable of Table

      The other table to merge with this one. If an iterable, the tables are expected to not have metadata.

    sample‘union’, ‘intersection’, optional

      How the sample axis is handled

    observation‘union’, ‘intersection’, optional

      How the observation axis is handled

    sample_metadata_f function, optional

      Defaults to `biom.util.prefer_self`. Defines how to handle sample metadata during merge.

    obesrvation_metadata_f function, optional

      Defaults to `biom.util.prefer_self`. Defines how to handle observation metdata during merge.

  Returns:
    biom.Table

      The merged table

  Notes

  - If `sample_metadata_f` and `observation_metadata_f` are None,

      then a fast merge is applied.

  - There is an implicit type conversion to `float`.

  - The return type is always that of `self`

  Examples

      >>> import numpy as np
      >>> from biom.table import Table

  Create a 2x2 table and a 3x2 table:

      >>> d_a = np.asarray([[2, 0], [6, 1]])
      >>> t_a = Table(d_a, ['O1', 'O2'], ['S1', 'S2'])
      >>> d_b = np.asarray([[4, 5], [0, 3], [10, 10]])
      >>> t_b = Table(d_b, ['O1', 'O2', 'O3'], ['S1', 'S2'])

  Merging the table results in the overlapping samples/observations (see O1 and S2) to be summed and the non-overlapping ones to be added to the resulting table (see S3).

      >>> merged_table = t_a.merge(t_b)
      >>> print(merged_table)
      # Constructed from biom file
      #OTU ID S1      S2
      O1      6.0     5.0
      O2      6.0     4.0
      O3      10.0    10.0