# Not able convert string to missing

**URL:** https://discourse.julialang.org/t/not-able-convert-string-to-missing/80032
**Category:** New to Julia
**Created:** [April 26, 2022, 6:55am UTC](https://discourse.julialang.org/t/not-able-convert-string-to-missing/80032 "2022-04-26T06:55:53Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![sai\_matcha](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/sai_matcha/32/35801_2.png) [@sai\_matcha](https://discourse.julialang.org/u/sai_matcha)
#### Post date: [April 26, 2022, 6:55am UTC](https://discourse.julialang.org/t/not-able-convert-string-to-missing/80032/1 "2022-04-26T06:55:53Z")

</div>

Hi,

I have a string variable in my dataframe. Im tryng to convert that to float 64. below is the process and problems im faced  
first i tried to convert string varaible to float64. Below is the error.

```julia
phen7[!,:ALB] = passmissing(parse).(Float64,phen7[!,:ALB])
ERROR: ArgumentError: cannot parse "" as Float64
Stacktrace:
  [1] _parse_failure(T::Type, s::String, startpos::Int64, endpos::Int64) (repeats 2 times)
    @ Base ./parse.jl:373
  [2] #tryparse_internal#452
    @ ./parse.jl:369 [inlined]
  [3] tryparse_internal
    @ ./parse.jl:367 [inlined]
  [4] #parse#453
    @ ./parse.jl:379 [inlined]
  [5] parse
    @ ./parse.jl:379 [inlined]
  [6] macro expansion
    @ ~/.julia/packages/Missings/r1STI/src/Missings.jl:0 [inlined]
  [7] PassMissing
    @ ~/.julia/packages/Missings/r1STI/src/Missings.jl:190 [inlined]
  [8] _broadcast_getindex_evalf
    @ ./broadcast.jl:670 [inlined]
  [9] _broadcast_getindex
    @ ./broadcast.jl:653 [inlined]
 [10] getindex
    @ ./broadcast.jl:597 [inlined]
 [11] macro expansion
    @ ./broadcast.jl:961 [inlined]
 [12] macro expansion
    @ ./simdloop.jl:77 [inlined]
 [13] copyto!
    @ ./broadcast.jl:960 [inlined]
 [14] copyto!
    @ ./broadcast.jl:913 [inlined]
 [15] copy
    @ ./broadcast.jl:885 [inlined]
 [16] materialize(bc::Base.Broadcast.Broadcasted{Base.Broadcast.DefaultArrayStyle{1}, Nothing, Missings.PassMissing{typeof(parse)}, Tuple{Base.RefValue{Type{Float64}}, Vector{String}}})
    @ Base.Broadcast ./broadcast.jl:860
 [17] top-level scope
    @ none:1

```

Then i tried to replace “” to missing, Below is the error.

```julia
julia> replace!(phen7.ALB, "" => missing)
ERROR: MethodError: Cannot `convert` an object of type Missing to an object of type String
Closest candidates are:
  convert(::Type{T}, ::P) where {T, P<:(Polynomials.AbstractPolynomial{T})} at ~/.julia/packages/Polynomials/DglHf/src/common.jl:433
  convert(::Type{String}, ::FilePathsBase.AbstractPath) at ~/.julia/packages/FilePathsBase/qgXdE/src/path.jl:117
  convert(::Type{String}, ::WeakRefStrings.WeakRefString) at ~/.julia/packages/WeakRefStrings/31nkb/src/WeakRefStrings.jl:81
  ...
Stacktrace:
 [1] setindex!(A::Vector{String}, x::Missing, i1::Int64)
   @ Base ./array.jl:903
 [2] _replace!(new::Base.var"#new#329"{Tuple{Pair{String, Missing}}}, res::Vector{String}, A::Vector{String}, count::Int64)
   @ Base ./set.jl:681
 [3] replace_pairs!
   @ ./set.jl:499 [inlined]
 [4] #replace!#328
   @ ./set.jl:489 [inlined]
 [5] replace!(A::Vector{String}, old_new::Pair{String, Missing})
   @ Base ./set.jl:489
 [6] top-level scope
   @ none:1

```

this is how my values look

```julia
julia> println(unique(phen7.ALB))
["", "3.5", "4.5", "2.2", "3.8", "2.9", "3.6", "4.0", "4.6", "1.8", "2.1", "3.9", "4.4", "3.4", "3.7", "4.1", "4.3", "4.2", "4.8", "2.5", "3.3", "3.2", "3.1", "2.3", "2.7", "3.0", "2.6", "2.8", "2.4", "1.7", "2.0", "1.9", "<1.5", "5.0", "5.1"]

```

Can some one help me to convert this at Float64.

Thanks

---

<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: [April 26, 2022, 7:05am UTC](https://discourse.julialang.org/t/not-able-convert-string-to-missing/80032/2 "2022-04-26T07:05:03Z")

</div>

Use `replace` rather than `replace!` - your values are stored in a `Vector{String}` which can’t hold values of type `Missing`.

So you want `parse.(Float64, replace(phen7.ALB, "" => missing))` but note that this will still fail as one of your values is `"<1.5"` which can’t be parsed as float - you’ll have to decide what number you want to assign to this.

---

<div class="post-metadata">

### Author: ![sai\_matcha](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/sai_matcha/32/35801_2.png) [@sai\_matcha](https://discourse.julialang.org/u/sai_matcha)
#### Post date: [April 26, 2022, 7:07am UTC](https://discourse.julialang.org/t/not-able-convert-string-to-missing/80032/3 "2022-04-26T07:07:29Z")

</div>

Thank you, i will assign another value for “\<1.5”
