Cannot insert the row to the data frame

I cannot insert the new row to the dataframe. Any suggestions? Thanks!

julia> my_data = DataFrame(A  = repeat(["test"], 5), B = repeat([100], 5), C = repeat(["100%"], 5))
5×3 DataFrame
 Row │ A       B      C      
     │ String  Int64  String 
─────┼───────────────────────
   1 │ test      100  100%
   2 │ test      100  100%
   3 │ test      100  100%
   4 │ test      100  100%
   5 │ test      100  100%

julia> new = pushfirst!(Array{Any, 1}(missing, ncol(my_data)-1), "new_test")
3-element Vector{Any}:
 "new_test"
 missing
 missing

julia> insert!.(eachcol(my_data), 3, new)
ERROR: MethodError: Cannot `convert` an object of type Missing to an object of type Int64
Closest candidates are:
  convert(::Type{T}, ::Ptr) where T<:Integer at pointer.jl:23
  convert(::Type{IT}, ::GeometryBasics.OffsetInteger) where IT<:Integer at /Users/xzhong/.julia/packages/GeometryBasics/wFus0/src/offsetintegers.jl:40
  convert(::Type{T}, ::SentinelArrays.ChainedVectorIndex) where T<:Union{Signed, Unsigned} at /Users/xzhong/.julia/packages/SentinelArrays/VbnBp/src/chainedvector.jl:209
  ...

This should work

push!(my_data,("mi",3,"ma"))

I suggest that you do not name a vector new as this is a reserved keyword (in some contexts) in Julia.
Also, the types of your new row are not compatible with the DataFrame.
Try this

allowmissing!(my_data)
nw = pushfirst!(Array{Any, 1}(missing, ncol(my_data)-1), "new_test")
push!(my_data,Tuple(nw)) 
2 Likes

Solved! Thanks!
The key point learned from you is:

allowmissing!(my_data)

Test:

julia> my_data = DataFrame(A  = repeat(["test"], 5), B = repeat([100], 5), C = repeat(["100%"], 5))
5×3 DataFrame
 Row │ A       B      C      
     │ String  Int64  String 
─────┼───────────────────────
   1 │ test      100  100%
   2 │ test      100  100%
   3 │ test      100  100%
   4 │ test      100  100%
   5 │ test      100  100%

julia> nw = pushfirst!(Array{Any, 1}(missing, ncol(my_data)-1), "new_test")
3-element Vector{Any}:
 "new_test"
 missing
 missing

julia> allowmissing!(my_data)
5×3 DataFrame
 Row │ A        B       C       
     │ String?  Int64?  String? 
─────┼──────────────────────────
   1 │ test        100  100%
   2 │ test        100  100%
   3 │ test        100  100%
   4 │ test        100  100%
   5 │ test        100  100%

julia> insert!.(eachcol(my_data), 3, nw)
3-element Vector{Vector{T} where T}:
 Union{Missing, String}["test", "test", "new_test", "test", "test", "test"]
 Union{Missing, Int64}[100, 100, missing, 100, 100, 100]
 Union{Missing, String}["100%", "100%", missing, "100%", "100%", "100%"]

julia> my_data
6×3 DataFrame
 Row │ A         B        C       
     │ String?   Int64?   String? 
─────┼────────────────────────────
   1 │ test          100  100%
   2 │ test          100  100%
   3 │ new_test  missing  missing 
   4 │ test          100  100%
   5 │ test          100  100%
   6 │ test          100  100%