skbio.table.Table.align_to_dataframe#
- Table.align_to_dataframe(metadata, axis='sample')[source]#
Aligns dataframe against biom table, only keeping common ids.
- Parameters:
- metadatapd.DataFrame
The metadata, either respect to the sample metadata or observation metadata.
- axis{‘sample’, ‘observation’}
The axis on which to operate.
- Returns:
- biom.Table
A filtered biom table.
- pd.DataFrame
A filtered metadata table.
Examples
>>> from biom import Table >>> import numpy as np >>> import pandas as pd >>> table = Table(np.array([[0, 0, 1, 1], ... [2, 2, 4, 4], ... [5, 5, 3, 3], ... [0, 0, 0, 1]]), ... ['o1', 'o2', 'o3', 'o4'], ... ['s1', 's2', 's3', 's4']) >>> metadata = pd.DataFrame([['a', 'control'], ... ['c', 'diseased'], ... ['b', 'control']], ... index=['s1', 's3', 's2'], ... columns=['Barcode', 'Treatment']) >>> res_table, res_metadata = table.align_to_dataframe(metadata) >>> print(res_table) # Constructed from biom file #OTU ID s1 s2 s3 o1 0.0 0.0 1.0 o2 2.0 2.0 4.0 o3 5.0 5.0 3.0 >>> print(res_metadata) Barcode Treatment s1 a control s2 b control s3 c diseased