Thanks for all the explanations and additional methods! Sorry I am still a little confused about the distinction between f.(eachcol(df))
, f.(enumerate(eachcol(df)))
, and f.(pairs(eachcol(df)))
and how to implement the latter two.
for col in eachcol(df)
for v in col::Vector{String}
println("$v today")
end
end
gives the desired result of
Marley sold out today
Kiiara sold out today
Sinead sold out today
Rynn sold out today
Illenium sold out today
Nelly sold out today
Likewise if I define
function f(x)
for i = x
println("$i today")
end
then both
julia> f.(eachcol(df))
and
map(f,eachcol(df))
yield
Marley sold out today
Kiiara sold out today
Sinead sold out today
Rynn sold out today
Illenium sold out today
Nelly sold out today
2-element Vector{Nothing}:
nothing
nothing
but
julia> f.(enumerate(eachcol(df)))
1 today
["Marley sold out", "Kiiara sold out", "Sinead sold out"] today
2 today
["Rynn sold out", "Illenium sold out", "Nelly sold out"] today
2-element Vector{Nothing}:
nothing
nothing
and
julia> f.(pairs(eachcol(df)))
ERROR: ArgumentError: broadcasting over dictionaries and `NamedTuple`s is reserved
Stacktrace:
[1] broadcastable(#unused#::Base.Pairs{Symbol, AbstractVector, Vector{Symbol}, DataFrames.DataFrameColumns{DataFrame}})
@ Base.Broadcast ./broadcast.jl:705
[2] broadcasted(::Function, ::Base.Pairs{Symbol, AbstractVector, Vector{Symbol}, DataFrames.DataFrameColumns{DataFrame}})
@ Base.Broadcast ./broadcast.jl:1295
[3] top-level scope
@ REPL[309]:1
Is this because with enumerate
and pairs
it is no longer a vector being inputted into the function? How does the function need to be modified for it to work? Sorry I’m sure I’m missing something simple here. I though maybe removing the row iteration in the function might work but
function g(x)
println("$x today")
end
yields
g.(enumerate(eachcol(df)))
(1, ["Marley sold out", "Kiiara sold out", "Sinead sold out"]) today
(2, ["Rynn sold out", "Illenium sold out", "Nelly sold out"]) today
2-element Vector{Nothing}:
nothing
nothing
and
g.(pairs(eachcol(df)))
ERROR: ArgumentError: broadcasting over dictionaries and `NamedTuple`s is reserved
Stacktrace:
[1] broadcastable(#unused#::Base.Pairs{Symbol, AbstractVector, Vector{Symbol}, DataFrames.DataFrameColumns{DataFrame}})
@ Base.Broadcast ./broadcast.jl:705
[2] broadcasted(::Function, ::Base.Pairs{Symbol, AbstractVector, Vector{Symbol}, DataFrames.DataFrameColumns{DataFrame}})
@ Base.Broadcast ./broadcast.jl:1295
[3] top-level scope
@ REPL[314]:1
other modifications to the function I’ve tried also yields errors.