I'm building a dataframe where for some of the columns, the obvious way to create them involves a multi-step process. I'd like to idiomatically and concisely create a column with eltype Union{Missing, T}. Then I can then fill the column using the multi-step process (and disallowmissing once finished as appropriate). What's the cleanest way to do this?
I'd like to do something like df[!, :col] :: Vector{Union{Int64, Missing}} .= missing but this gives "ArgumentError: column name :col not found in the data frame; ..."
If I try to do df[!, :col] .= fill(missing, nrow(df)) :: Vector{Union{Int64, Missing}}, I get "TypeError: in typeassert, expected Vector{Union{Missing, Int64}}, got a value of type Vector{Missing}".
For the moment I'm doing something ugly and confusing, like
df[!, :col] .= 0
allowmissing!(df, :col)
df.col .= missing
Any suggestions? My sense is that if I have this question, I don't really understand the nuances of how column typing in DataFrames.jl works, even though I use it all the time and generally don't have problems. I've searched the documentation and don't feel like I've seen anything that would help with this specific issue, but any recommended reading would be appreciated.
Thanks!