I tried to read the transform
doc for DataFrames.jl and I have to say it’s tough going. But I think it contains lots of info.
The situation I want to discuss is actually documented in the doc but the question, how do I return multiple columns from a function
in the cols => function => target_cols
triplet syntax?
Based, to make it work you need function
to return a NamedTuple
and returning a Tuple
doesn’t work.
I feel this is unintuitive. What are the considerations that go into making returning a Tuple
to cause errors? For example, we can check if the output of the function
is a tuple and dispatch on that somehow right?
using DataFrames
b=DataFrame(val=rand(100))
function do2(val::AbstractArray)
println("ok3")
(meh=val/2, ok=val/3)
end
# approach 1 requiring the function to return NamedTuple worked
b2 = transform(b, :val => do2 => [:a, :b]);
function do3(val::AbstractArray)
println("ok4")
(val / 2, val / 3)
end
# approach fails.
b2 = transform(b, :val => do3 => [:a, :b]);
PS. how do I return multiple columns using a framework such as DataFramesMeta.jl or DataFramesMacros.jl or TiderData.jl?