Hi, I am a new Julia user and I am having difficulty imputing missing values in my dataframe. The replacement value is dependent on the position of the column and other values in that row. Coming from a Java background, I adopted loops. i.e.,
for row_counter in 1:size(df,1)
for column_counter in 1:size(df,2)
if ismissing(df[row_counter,column_counter])
next_val = get_next_non_missing_val(df[row_counter,:],column_counter) # get the next non missing value for that row
if column_counter==0
if next_val==-1 # custom logic
next_val = 100
end
df[row_counter,column_counter]=next_val
elseif column_counter==size(df,2)
df[row_counter,column_counter]=df[row_counter,column_counter-1]
else
if next_val==-1
next_val=df[row_counter,column_counter-1]
end
df[row_counter,column_counter] = (df[row_counter,column_counter-1]+next_val)/2
println(df[row_counter,column_counter] )
end
end
end
end
However, I keep getting the following error:
ERROR: LoadError: MethodError: convert(::Type{Union{}}, ::Float64) is ambiguous. Candidates:
convert(::Type{Union{}}, x) in Base at essentials.jl:169
convert(::Type{T}, x::Number) where T<:Number in Base at number.jl:7
convert(::Type{T}, arg) where T<:VecElement in Base at baseext.jl:8
convert(::Type{T}, x::Number) where T<:AbstractChar in Base at char.jl:179
Possible fix, define
convert(::Type{Union{}}, ::Number)
I believe this is due the fact that as my dataframe has missing values, its considered is considered as Union, but I don’t know how to resolve this issue. Can someone please help me and also advise if the methodology I adopted to impute the missing values is the efficient?