# Creating an empty list and adding elements to it

**URL:** <https://discourse.julialang.org/t/creating-an-empty-list-and-adding-elements-to-it/90479>\
**Category:** General Usage\
**Created:** [November 19, 2022, 1:41am UTC](https://discourse.julialang.org/t/creating-an-empty-list-and-adding-elements-to-it/90479 "2022-11-19T01:41:30Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![FH96](https://avatars.discourse-cdn.com/v4/letter/f/4da419/32.png) [@FH96](https://discourse.julialang.org/u/FH96)\
**Post date:** [November 19, 2022, 1:41am UTC](https://discourse.julialang.org/t/creating-an-empty-list-and-adding-elements-to-it/90479/1 "2022-11-19T01:41:30Z")

</div>

Hi!

I want to make an empty list or vector or dataframe and add elements which are of tyep `String31` to it. But trying the dataframe option and `push!` I face this error:

" ArgumentError: it is not allowed to insert collections of type String31 into a DataFrame. Only `Tuple`, `AbstractArray`, `AbstractDict`, `DataFrameRow`  
and `NamedTuple` are allowed."  
I appreciate any help!

---

<div class="post-metadata">

**Author:** ![nilshg](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nilshg/32/2283_2.png) [@nilshg](https://discourse.julialang.org/u/nilshg)\
**Post date:** [November 19, 2022, 6:21am UTC](https://discourse.julialang.org/t/creating-an-empty-list-and-adding-elements-to-it/90479/2 "2022-11-19T06:21:43Z")

</div>

The error message tells you what’s wrong: `push!` needs one of the specified collection types when used with a DataFrame. This is because you can only push rows to the DataFrame, not single values (which wouldn’t make much sense as all columns have to have the same length).

If your DataFrame has only one column, try replacing `push!(df, x)` with `push!(df, (x,))` which creates a Tuple from your value to add it to the DataFrame. If you have more than one column, you need to provide a value for each column, ie `push!(df, (x, y, z))`

---

<div class="post-metadata">

**Author:** ![FH96](https://avatars.discourse-cdn.com/v4/letter/f/4da419/32.png) [@FH96](https://discourse.julialang.org/u/FH96)\
**Post date:** [November 19, 2022, 9:59am UTC](https://discourse.julialang.org/t/creating-an-empty-list-and-adding-elements-to-it/90479/3 "2022-11-19T09:59:58Z")

</div>

Thanks a lot!  
I understood that I should transform it into a tuple or other things mentioned in the error but I didn’t know how! `(x,)` was the key  
If I want to add several items using `append!`, What should I do?

---

<div class="post-metadata">

**Author:** ![nilshg](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nilshg/32/2283_2.png) [@nilshg](https://discourse.julialang.org/u/nilshg)\
**Post date:** [November 19, 2022, 10:49am UTC](https://discourse.julialang.org/t/creating-an-empty-list-and-adding-elements-to-it/90479/4 "2022-11-19T10:49:56Z")

</div>

If you use `append!` it’s probably best to just create a DataFrame out of the items you want to append (if you have the columns as vectors)
