How can I make an Array{Array{Float64,1},1} out of two columns of a dataframe?

I have a dataframe with two columns x,y of type Float. I want to apply the concave_hull() function of the ConcaveHull package on those columns. But it prefers a [[1.0,2.0],[3.0,4.0],...] object. How can I now convert the columns to that object? I’ve struggled quite a bit with this. Many thanks in advance!

collect(eachcol(df))

Hmm… unfortunately this gives me sth else…

df = DataFrame(x=rand(10) , y=rand(10));
collect(eachcol(df))

gives a 2-element Array{AbstractArray{T,1} where T,1}, but not the required 10-element Array{Array{Float64,1},1}

The poor man’s way works fine if this is the only time you need it: [df.x, df.y]

1 Like

Ah sorry you want

julia> collect.(eachrow(df))
2 Likes

Okay, I found a (poor man’s) way:

df = DataFrame(x=rand(10) , y=rand(10));

[[df.x[i],df.y[i]] for i in 1:nrow(df)]

… gives me a 10-element Array{Array{Float64,1},1}

Did you try collect.(eachrow(df))?

julia> df = DataFrame(x = rand(10), y = rand(10));

julia> collect.(eachrow(df))
10-element Array{Array{Float64,1},1}:
 [0.35424724279497966, 0.4697299328665443]
 [0.36738913473583823, 0.9304579561346957]
 [0.005508085955786779, 0.567222362963131]
 [0.5482079525456292, 0.5794345832007906]
 [0.9080293755772335, 0.11550368172702608]
 [0.8068866112091113, 0.22230162714717272]
 [0.9464827600585084, 0.4709336111872562]
 [0.9161280652731476, 0.8620815301389604]
 [0.5261048454418709, 0.20695828316038356]
 [0.6150559269084683, 0.9246450679267724]
1 Like