# Add a column of ints to a DataFrame of strings

**URL:** <https://discourse.julialang.org/t/add-a-column-of-ints-to-a-dataframe-of-strings/4976>\
**Category:** General Usage\
**Tags:** question, packages\
**Created:** [July 20, 2017, 12:52pm UTC](https://discourse.julialang.org/t/add-a-column-of-ints-to-a-dataframe-of-strings/4976 "2017-07-20T12:52:26Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![e3c6](https://avatars.discourse-cdn.com/v4/letter/e/e79b87/32.png) [@e3c6](https://discourse.julialang.org/u/e3c6)\
**Post date:** [July 20, 2017, 12:52pm UTC](https://discourse.julialang.org/t/add-a-column-of-ints-to-a-dataframe-of-strings/4976/1 "2017-07-20T12:52:26Z")

</div>

How to add an int column to a DataFrame of strings?

```julia
d = DataFrames.DataFrame([["hello", "world"]], [:strs])
d[:num] = [1,2]

```

gives an error:

> MethodError: Cannot `convert` an object of type Int64 to an object of type String  
> This may have arisen from a call to the constructor String(…),  
> since type constructors fall back to convert methods.

But this works:

```julia
d[:num] = ["a","b"]

```

I thought columns of DataFrame need not have the same type.

---

<div class="post-metadata">

**Author:** ![kristoffer.carlsson](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/kristoffer.carlsson/32/22_2.png) [@kristoffer.carlsson](https://discourse.julialang.org/u/kristoffer.carlsson)\
**Post date:** [July 20, 2017, 1:15pm UTC](https://discourse.julialang.org/t/add-a-column-of-ints-to-a-dataframe-of-strings/4976/2 "2017-07-20T13:15:20Z")

</div>

[https://github.com/JuliaStats/DataFrames.jl/blob/ff8cd116c59dc64f45ff73f67c605bb5c66fd071/src/dataframe/dataframe.jl#L73](https://github.com/JuliaStats/DataFrames.jl/blob/ff8cd116c59dc64f45ff73f67c605bb5c66fd071/src/dataframe/dataframe.jl#L73) should perhaps be `Vector{Any}`.

---

<div class="post-metadata">

**Author:** ![kristoffer.carlsson](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/kristoffer.carlsson/32/22_2.png) [@kristoffer.carlsson](https://discourse.julialang.org/u/kristoffer.carlsson)\
**Post date:** [July 20, 2017, 1:19pm UTC](https://discourse.julialang.org/t/add-a-column-of-ints-to-a-dataframe-of-strings/4976/3 "2017-07-20T13:19:01Z")

</div>

I made a PR that should fix this but not sure if it has performance problems: [https://github.com/JuliaStats/DataFrames.jl/pull/1201](https://github.com/JuliaStats/DataFrames.jl/pull/1201)
