I have a SQLite database that I read into a DataFrame in Julia. When values are missing, they are given type SQLite.Null, which is difficult to deal with. I would prefer that they were NAs. Is there an easy way to do this conversion? My kludgy way is as follows:
using DataFrames, SQLite
df = DataFrame()
df[:x1] = [1, SQLite.NullType(), 3, 4]
df[:x2] = ["A", "B", SQLite.NullType(), "D"]
function repNull(x)
if isa(x, SQLite.NullType)
return(NA)
else
return(x)
end
end
df[:1] = map(repNull, df[:x1])
df[:2] = map(repNull, df[:x2])
Is there a more elegant and/or efficient way?
I've looked for this question but I'm very new to Julia so I may have been using the wrong terms.
Aucun commentaire:
Enregistrer un commentaire