# How to add new columns in Hail table?

**URL:** <https://discuss.hail.is/t/how-to-add-new-columns-in-hail-table/2372>\
**Category:** Hail Query & hailctl\
**Created:** [November 25, 2021, 4:37am UTC](https://discuss.hail.is/t/how-to-add-new-columns-in-hail-table/2372 "2021-11-25T04:37:44Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Gopi](https://avatars.discourse-cdn.com/v4/letter/g/7cd45c/32.png) [@Gopi](https://discuss.hail.is/u/Gopi)\
**Post date:** [November 25, 2021, 4:37am UTC](https://discuss.hail.is/t/how-to-add-new-columns-in-hail-table/2372/1 "2021-11-25T04:37:44Z")

</div>

Hi,  
`MatrixTable` 's `annotate_cols` adds new column fields. `Table` 's `annotate` adds new row fields.

Is there any way to add a new column to the hail table? We tried the below code but its throwing the following error “TypeError: ‘Table’ object does not support item assignment”

Code: ht[‘esp6500siv2\_all’] = ht[‘AA\_AF’]+ht[‘EA\_AF’]

Regards,  
Gopi

---

<div class="post-metadata">

**Author:** ![tpoterba](https://yyz2.discourse-cdn.com/flex036/user_avatar/discuss.hail.is/tpoterba/32/61_2.png) [@tpoterba](https://discuss.hail.is/u/tpoterba)\
**Post date:** [November 25, 2021, 2:25pm UTC](https://discuss.hail.is/t/how-to-add-new-columns-in-hail-table/2372/2 "2021-11-25T14:25:11Z")

</div>

We try to avoid calling table fields “columns” because “column” has a particular meaning for matrix tables, and also often connotes homogenous kinds of data between columns.

The analog of a Pandas DataFrame ‘column’ is a **table row field**. `annotate` is exactly what you need here:

```auto
ht = ht.annotate(esp6500siv2_all = ht[‘AA_AF’]+ht[‘EA_AF’])

```

---

<div class="post-metadata">

**Author:** ![jjfarrell](https://yyz2.discourse-cdn.com/flex036/user_avatar/discuss.hail.is/jjfarrell/32/108_2.png) [@jjfarrell](https://discuss.hail.is/u/jjfarrell)\
**Post date:** [March 12, 2024, 1:02pm UTC](https://discuss.hail.is/t/how-to-add-new-columns-in-hail-table/2372/3 "2024-03-12T13:02:10Z")

</div>

Is there a way to specify the location of the new fields? For example, creating FID and IID fields to place in the first 2 collumns of the table. The default is to add them at the end.

---

<div class="post-metadata">

**Author:** ![patrick-schultz](https://yyz2.discourse-cdn.com/flex036/user_avatar/discuss.hail.is/patrick-schultz/32/265_2.png) [@patrick-schultz](https://discuss.hail.is/u/patrick-schultz)\
**Post date:** [March 12, 2024, 4:47pm UTC](https://discuss.hail.is/t/how-to-add-new-columns-in-hail-table/2372/4 "2024-03-12T16:47:33Z")

</div>

Generally we don’t consider the order of fields significant. Why do you want them first?

---

<div class="post-metadata">

**Author:** ![danking](https://yyz2.discourse-cdn.com/flex036/user_avatar/discuss.hail.is/danking/32/43_2.png) [@danking](https://discuss.hail.is/u/danking)\
**Post date:** [March 12, 2024, 5:10pm UTC](https://discuss.hail.is/t/how-to-add-new-columns-in-hail-table/2372/5 "2024-03-12T17:10:11Z")

</div>

I assume you want this for export. I think the only way to achieve this is:

```python
key = ht.key
ht = ht.key_by()
ht = ht.order_by(*key)
ht = ht.select(fields, in, the, order, you, want, ...)
ht.export(...)

```
