Hello,
Following https://github.com/JuliaData/DataFrames.jl/issues/1854 I wonder if tryparse implementation shouldn't have an argument to output missing instead of nothing.
So it will be possible to simply do
julia> using DataFrames
julia> df = DataFrame(:A=>["", "2", "3"], :B=>[1.1, 2.2, 3.3])
3ร2 DataFrame
โ Row โ A โ B โ
โ โ String โ Float64 โ
โโโโโโโผโโโโโโโโโผโโโโโโโโโโค
โ 1 โ โ 1.1 โ
โ 2 โ 2 โ 2.2 โ
โ 3 โ 3 โ 3.3 โ
julia> df.A = tryparse.(Int, df.A, missing)
3-element Array{Union{Missing, Int64},1}:
missing
2
3
julia> df
3ร2 DataFrame
โ Row โ A โ B โ
โ โ Int64โฐ โ Float64 โ
โโโโโโโผโโโโโโโโโโผโโโโโโโโโโค
โ 1 โ missing โ 1.1 โ
โ 2 โ 2 โ 2.2 โ
โ 3 โ 3 โ 3.3 โ
Your opinion?
Kind regards
The value is not missing here. If you want missing just wrap tryparse in a function that transform nothing to missing.
Yeah, this should be as simple as doing mytryparse(T, str) = something(tryparse(T, str), missing)
Maybe the discussion should continue in https://github.com/JuliaData/Missings.jl/issues/61
Most helpful comment
Yeah, this should be as simple as doing
mytryparse(T, str) = something(tryparse(T, str), missing)