I have a DataFrame with multiple columns of type Union{Missing, String}. What is the most concise manner of converting the non-missing values in Float?

Hi! I have a DataFrame with multiple columns of type Union{Missing, String}. What is the most concise manner of converting the non-missing values in Float?

(Original message :slack:)

1 Like

If you want to retain the missing values in their original positions I think the best way is

julia> passmissing(parse).(Float64, ["1", "3.14159", missing])
3-element Vector{Union{Missing, Float64}}:
 1.0
 3.14159
  missing
1 Like

copying from slack, turns out OP wants missing to become NaN:

f(x) = x===missing ? NaN : parse(Float64, x)
df.mycol = f.(df.mycol)
2 Likes