Frequent error



I am new here and I do get this error often…I revise my code several time…I didnot specify the type of the variables in my function yet I get this error when I call the function…What is the meaning of this error as it seems to me like I donot get it and how do I fix it ?

Thank you

so it looks like you have a DataFrame whose column already have types, for example this could be what you’re doing:

julia> df
3×2 DataFrame│ Row │ a       │ b      │
│     │ Float64 │ String │
│ 1   │ 1.0     │ x      │
│ 2   │ 1.0     │ y      │
│ 3   │ 1.0     │ γ      │

julia> df.b .= "a"3-element Array{String,1}:

julia> df.a .= "a"
ERROR: MethodError: Cannot `convert` an object of type String to an object of type Float64
Closest candidates are:
  convert(::Type{T}, ::T) where T<:Number at number.jl:6
  convert(::Type{T}, ::Number) where T<:Number at number.jl:7
  convert(::Type{T}, ::Base.TwicePrecision) where T<:Number at twiceprecision.jl:250
 [1] fill!(::Array{Float64,1}, ::String) at ./array.jl:336
 [2] copyto! at ./broadcast.jl:872 [inlined]
 [3] materialize!(::Array{Float64,1}, ::Base.Broadcast.Broadcasted{Base.Broadcast.DefaultArrayStyle{0},Nothing,typeof(identity),Tuple{Base.RefValue{String}}}) at ./broadcast.jl:823
 [4] top-level scope at REPL[10]:1

if you need to replace the column, you need the following syntax:

df[!, :a] .= "a"

to change the type of the column entirely


Btw. The error is probably on line 93 of general.jl as shown in your screenshot.

If you have not solved this already, maybe you could post the code from that file.

1 Like

Thank you

yes solved it …Thank you