I am trying to replace missing values in Float coluns with 0.0.
My starting point:
for col in names(df)
df[ismissing.(df[col]), col] = 0.0
end
While this works, it has two weak points:
a. it doesnβt check the type of the column; only in Float colums
missing shall be replaced with 0.0
b. it throws a warning
just use df[!, col] = [ismissing(x) ? 0.0 .... Alternatively if you upgrade to the most recent version of DataFrames (released today), you that will work without a warning message.
The comments above are better as exact solutions to OPβs question, but I thought some people may find it interesting to know how to do this with MLJ:
The fill imputer can use other filling rules like the mean of the column or its median. The keyword continuous_fill takes a function to apply to βcontinuousβ features as opposed to count_fill / finite_fill which take functions for count-data / categorical data.
A bit outside the scope of the question but Float64 <: Union{Float64, Missing} does the latter. See also this post on retrieving the non-missing type and corresponding pointer to Missings.jl.