Reputation: 1
i am rather new to julia so apologies if this is a rather trivial question. However I have stumbled upon a problem i cannot resolve so appreciate any help/suggestions.
I have a function which returns a set of values in a dataframe when I run it. Something along the lines of:
(values) = function(data)
However I run this function in
[for example see here][1]
I run this function in a loop so that each time it runs, I get a new set of values.
for x = 1:5
(values) = function(data[data[:sub].==[x], :])
end
After the function runs, I then want to put the values that come back into a "master" data frame which has exactly the same column headings and compiles the values that come back on each loop iteration.
This seems infuriatingly tricky to do. I tried using append!
as described here:
https://discourse.julialang.org/t/adding-a-new-row-to-a-dataframe/1331/3
But this does not work. For example if I run the following commands
(values_1) = function(data[data[:sub].==[1], :])
(values_2) = function(data[data[:sub].==[2], :])
append(values_1, values_2)
This fails with the following error message:
MethodError: no method matching append!(::Array{Float64,2}, ::Array{Float64,2})
Closest candidates are:
append!(::PyCall.PyObject, ::Any) at /Users/neil/.julia/v0.5/PyCall/src/PyCall.jl:836
append!(::Array{T,1}, ::Any) at collections.jl:21
append!{T}(::PyCall.PyVector{T}, ::Any) at /Users/neil/.julia/v0.5/PyCall/src/conversions.jl:278
in append!(::DataFrames.DataFrame, ::DataFrames.DataFrame) at /Users/neil/.julia/v0.5/DataFrames/src/dataframe/dataframe.jl:791
in include_string(::String, ::String) at ./loading.jl:441
in include_string(::String, ::String) at /Applications/Julia-0.5.app/Contents/Resources/julia/lib/julia/sys.dylib:?
Note that the function does correctly return a dataframe each time I run it, it is just the concatanation of values that is causing problems.
appreciate any pointers. n
Upvotes: 0
Views: 2455
Reputation: 8044
You're looking for vcat
, e.g. vcat(values_1, values_2)
. There might be a better way to do what you're doing, though, but it's hard to give specific advice without an 'MWE', i.e. an example we can paste into a terminal, run and rewrite.
Upvotes: 2