As a newcomer to Julia and JuliaDB, I have a simple question. Given a JuliaDB table, how would I map a function to a column that changes the column values and type? For example:
import JuliaDB
import Dates
function col_to_dt(val)
dt = Dates.Date(replace(val, "|" => "-"))
end
t = JuliaDB.table(["2015|03|01", "2016|02|05"]; names = [:dt])
JuliaDB.select(t, :dt => x -> col_to_dt(x))
The above code does not change t.dt. It remains a string. Also, in this example, how would you use JuliaDBMeta.@apply
to conduct a series of steps to alter a column’s values and type?
Added Later:
I see that the following creates a new table and saves it under the same name:
t = JuliaDB.transform(t, :dt => JuliaDB.select(t, :dt => col_to_dt))
Would this be the recommended approach?
Still, how could this be arranged within a JuliaDBMeta.@apply
call? The following does not work:
import JuliaDBMeta
import JuliaDB
import Dates
t = JuliaDB.table(["2015|03|01", "2016|02|05"], [2,4]; names = [:dt, :num])
t = JuliaDBMeta.@apply t begin
JuliaDBMeta.@transform(dt = JuliaDBMeta.@select(t, :dt => col_to_dt))
end
It gives the error:
ERROR: LoadError: LoadError: column 2015|03|01 not found.