# Append one line to similar DataFrame gives eltype error

**URL:** https://discourse.julialang.org/t/append-one-line-to-similar-dataframe-gives-eltype-error/7763
**Category:** Data
**Tags:** data, dataframes
**Created:** [December 14, 2017, 2:59pm UTC](https://discourse.julialang.org/t/append-one-line-to-similar-dataframe-gives-eltype-error/7763 "2017-12-14T14:59:08Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![Fred](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/fred/32/14175_2.png) [@Fred](https://discourse.julialang.org/u/Fred)
#### Post date: [December 14, 2017, 2:59pm UTC](https://discourse.julialang.org/t/append-one-line-to-similar-dataframe-gives-eltype-error/7763/1 "2017-12-14T14:59:08Z")

</div>

Hi,

I try top append a line to 2 similar DataFrames, using the strategy described here before DataFrame recent update :

> [@Adding a new row to a DataFrame](https://discourse.julialang.org/t/adding-a-new-row-to-a-dataframe/1331/3):
>
> To add a row, you can merge 2 dataframes : julia\> df = DataFrame(A = 1:4, B = ["M", "F", "F", "M"]) 4×2 DataFrames.DataFrame │ Row │ A │ B │ ├─────┼───┼─────┤ │ 1 │ 1 │ "M" │ │ 2 │ 2 │ "F" │ │ 3 │ 3 │ "F" │ │ 4 │ 4 │ "M" │ julia\> df2 = DataFrame(A = 6, B = ["F"]) 1×2 DataFrames.DataFrame │ Row │ A │ B │ ├─────┼───┼─────┤ │ 1 │ 6 │ "F" │ julia\> append!(df,df2) 5×2 DataFrames.DataFrame │ Row │ A │ B │ ├─────┼───┼─────┤ │ 1 │ 1 │ "M" │ │ 2 │ 2 │ "F" │ │ 3 │ 3 │ "F" │ │ 4 …

But I have some problem because I do not manage to use append!() function without eltype error. Since the 2 DataFrames are similar, I expect the columns to have the same eltype.

Thank you for your help !

```julia
julia> typeof(x)
DataFrames.DataFrame

julia> y = similar(x,0)
0×6 DataFrames.DataFrame

julia> typeof(y)
DataFrames.DataFrame

julia> append!(y, x[4,:])
ERROR: Column eltypes do not match
Stacktrace:
 [1] append!(::DataFrames.DataFrame, ::DataFrames.DataFrame) at /home/fred/.julia/v0.6/DataFrames/src/dataframe/dataframe.jl:778

julia> eltypes(x)
6-element Array{Type,1}:
 WeakRefString{UInt8}                       
 CategoricalArrays.CategoricalString{UInt32}
 CategoricalArrays.CategoricalString{UInt32}
 CategoricalArrays.CategoricalString{UInt32}
 CategoricalArrays.CategoricalString{UInt32}
 Float64                                    

julia> eltypes(y)
6-element Array{Type,1}:
 Union{Missings.Missing, WeakRefString{UInt8}}                       
 Union{CategoricalArrays.CategoricalString{UInt32}, Missings.Missing}
 Union{CategoricalArrays.CategoricalString{UInt32}, Missings.Missing}
 Union{CategoricalArrays.CategoricalString{UInt32}, Missings.Missing}
 Union{CategoricalArrays.CategoricalString{UInt32}, Missings.Missing}
 Union{Float64, Missings.Missing}

```

---

<div class="post-metadata">

### Author: ![Fred](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/fred/32/14175_2.png) [@Fred](https://discourse.julialang.org/u/Fred)
#### Post date: [December 18, 2017, 7:56am UTC](https://discourse.julialang.org/t/append-one-line-to-similar-dataframe-gives-eltype-error/7763/2 "2017-12-18T07:56:41Z")

</div>

I found a solution, not very elegant but it works : since similar() does not produce exactly the same eltypes for the column, a solution is to make a copy of one line :

```julia
julia> append!(y, x[4,:])
ERROR: Column eltypes do not match

julia> z = copy(x[4,:])
1×6 DataFrames.DataFrame. Omitted printing of 4 columns

julia> append!(z, x[5,:])
2×6 DataFrames.DataFrame. Omitted printing of 4 columns

```

---

<div class="post-metadata">

### Author: ![nalimilan](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nalimilan/32/147_2.png) [@nalimilan](https://discourse.julialang.org/u/nalimilan)
#### Post date: [December 18, 2017, 9:01am UTC](https://discourse.julialang.org/t/append-one-line-to-similar-dataframe-gives-eltype-error/7763/3 "2017-12-18T09:01:23Z")

</div>

AFAIK this should be fixed in DataFrames master, should be in the ~~last~~ next release:  
[https://github.com/JuliaData/DataFrames.jl/pull/1298](https://github.com/JuliaData/DataFrames.jl/pull/1298)

---

<div class="post-metadata">

### Author: ![Fred](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/fred/32/14175_2.png) [@Fred](https://discourse.julialang.org/u/Fred)
#### Post date: [December 18, 2017, 9:38am UTC](https://discourse.julialang.org/t/append-one-line-to-similar-dataframe-gives-eltype-error/7763/4 "2017-12-18T09:38:29Z")

</div>

thank you @nalimilan for this good news 😉
