# Add column with a particular type in datasets

**URL:** <https://discuss.huggingface.co/t/add-column-with-a-particular-type-in-datasets/95674>\
**Category:** 🤗Datasets\
**Created:** [July 5, 2024, 9:26am UTC](https://discuss.huggingface.co/t/add-column-with-a-particular-type-in-datasets/95674 "2024-07-05T09:26:47Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![varadhbhatnagar](https://sea2.discourse-cdn.com/hellohellohello/user_avatar/discuss.huggingface.co/varadhbhatnagar/32/31383_2.png) [@varadhbhatnagar](https://discuss.huggingface.co/u/varadhbhatnagar)\
**Post date:** [July 5, 2024, 9:26am UTC](https://discuss.huggingface.co/t/add-column-with-a-particular-type-in-datasets/95674/1 "2024-07-05T09:26:47Z")

</div>

I want to add a column of type `int32` to a dataset object. Currently I am using `add_column()`with a `list` of integers which leads to columns with type `int64`, followed by `cast_column()`. As I am iteratively loading a lot of datasets and then concatenating them, the above process is too slow.

I was wondering if there is a way to specify a datatype while invoking `add_column()` itself ?

@sgugger @lhoestq

I checked the discussion below but did not find an answer to my question.

> [@How to add a new column to a dataset](https://discuss.huggingface.co/t/how-to-add-a-new-column-to-a-dataset/6453):
>
> How can I add a new column to my dataset? I am working on Cosmos QA dataset and need to add a new column of the following format: Value(dtype=‘string’, id=None) The current dataset has the following features: Dataset({ features: [‘id’, ‘context’, ‘question’, ‘answer0’, ‘answer1’, ‘answer2’, ‘answer3’, ‘label’], num\_rows: 25262 }) Thank you in advance!

---

<div class="post-metadata">

**Author:** ![lhoestq](https://sea2.discourse-cdn.com/hellohellohello/user_avatar/discuss.huggingface.co/lhoestq/32/52888_2.png) [@lhoestq](https://discuss.huggingface.co/u/lhoestq)\
**Post date:** [July 5, 2024, 9:47am UTC](https://discuss.huggingface.co/t/add-column-with-a-particular-type-in-datasets/95674/2 "2024-07-05T09:47:41Z")

</div>

As a workaround you can pass a numpy array with the right type

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/hellohellohello/original/2X/d/de4155eb4aa4108ecb32a1389d7cc37ae69f88b7.png) [@system](https://discuss.huggingface.co/u/system)\
**Post date:** [July 5, 2024, 9:47pm UTC](https://discuss.huggingface.co/t/add-column-with-a-particular-type-in-datasets/95674/3 "2024-07-05T21:47:59Z")

</div>

This topic was automatically closed 12 hours after the last reply. New replies are no longer allowed.
