# Convert pd.DataFrame to Metadata?

**URL:** https://forum.qiime2.org/t/convert-pd-dataframe-to-metadata/9540
**Category:** Technical Support
**Tags:** import
**Created:** [May 6, 2019, 8:19am UTC](https://forum.qiime2.org/t/convert-pd-dataframe-to-metadata/9540 "2019-05-06T08:19:01Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![jwchen](https://forum.qiime2.org/user_avatar/forum.qiime2.org/jwchen/32/3841_2.png) [@jwchen](https://forum.qiime2.org/u/jwchen)
#### Post date: [May 6, 2019, 8:19am UTC](https://forum.qiime2.org/t/convert-pd-dataframe-to-metadata/9540/1 "2019-05-06T08:19:01Z")

</div>

Hi,

I am using qiime2's python API (version 2019.1) now and it's pretty good. I am wondering if there is any way to convert pd.DataFrame back to metadata? Or I have to export the dataframe as .tsv file and reload the metadata again?

Thanks.

Jiung-Wen

---

<div class="post-metadata">

### Author: ![jwdebelius](https://forum.qiime2.org/user_avatar/forum.qiime2.org/jwdebelius/32/9655_2.png) [@jwdebelius](https://forum.qiime2.org/u/jwdebelius)
#### Post date: [May 6, 2019, 8:27am UTC](https://forum.qiime2.org/t/convert-pd-dataframe-to-metadata/9540/2 "2019-05-06T08:27:30Z")

</div>

Hi @jwchen,

I just pass my metadata into the `Metadata` object:

```python
from qiime2 import Metadata
meta_df = pd.read_csv('my_metadata.tsv', sep='\t').set_index('sample_id')
meta_q2 = Metdata(meta)

```

There are a couple of caveats. If you've been using the nifty pandas Categorical types to handle your data for ordinal stuff, QIIME will not be happy. I'm also not sure if it automagically casts your numbers, either, so I'd watch that.

Best,  
Justine

---

<div class="post-metadata">

### Author: ![jwchen](https://forum.qiime2.org/user_avatar/forum.qiime2.org/jwchen/32/3841_2.png) [@jwchen](https://forum.qiime2.org/u/jwchen)
#### Post date: [May 6, 2019, 3:06pm UTC](https://forum.qiime2.org/t/convert-pd-dataframe-to-metadata/9540/3 "2019-05-06T15:06:19Z")

</div>

Thank you Justine!! It works!!
