Replacing *missing* and *NaN* values in dataframe

Your indexing does not make sense: what is df_i.col supposed to mean?

julia> df_i.col
ERROR: ArgumentError: column name :col not found in the data frame

To replace all missings use coalesce:

julia> coalesce.(df_i, 0.0)
5×4 DataFrame
 Row │ id     name  age      salary
     │ Int64  Any   Float64  Float64
─────┼───────────────────────────────
   1 │   101  A        28.0   3200.0
   2 │   102  B        32.0   3200.0
   3 │   103  C         0.0   4500.0
   4 │   104  NaN     NaN        0.0
   5 │   105  E        31.0      0.0

if you want to loop over columns, just do so directly:

julia> for c ∈ eachcol(df_i)
           replace!(c, NaN => 0.0)
       end

I’d also recommend going through https://github.com/bkamins/Julia-DataFrames-Tutorial to get the hang of DataFrames

2 Likes