Hi all, I have a question regarding how to correctly solve this:
I have a DataFrame
that has the following columns:
df.i1 = [[1,2,3,4,5,1,2],[1,2,3,4,5,6,8,10,11],[1,2,3,4,5]]
df.i2 = [[4,2,1],[3,3,3],[1,2,2]]
And I need to generate three new columns, that have the values from df.i1
using the indexes from df.i2
, so the result should be something like this: following df.i1
, the first slice for the first item should go from 1 to 4, the following one from 4+1
to 4+2
, and the last one from 4+2+1
to 4+2+1
(which is also the total length of the sequence, as df.i2
is generated by using the rle
function in another column)
df.v1 = [[1,2,3,4],[1,2,3],[1]]
df.v2 = [[5,1],[4,5,6],[2,3]]
df.v3 = [[2],[8,10,11],[4,5]]
So far I tried using something like this:
for i in eachrow(df)
mi = i.i[1]
df_a.v1 = [x[1:mi] for x in i.zeros]
end
That can be extended to the other two cases, but I am getting the following error:
MethodError: no method matching getindex(::Int64, ::UnitRange{Int64})
Any help is welcome, I suppose that I am on the right track by looping over the rows of the df and trying to generate the slices that way, but I might be wrong.
Thanks!
Cheers.