daru icon indicating copy to clipboard operation
daru copied to clipboard

Insert column/row into DataFrame at specified location.

Open kojix2 opened this issue 6 years ago • 8 comments

Hello. Daru::DataFrame doesn't seem to have insert function.

set_at or set_row_at will overwrite. []= add_vector does not specify the insertion location.

kojix2 avatar Apr 19 '19 09:04 kojix2

[]= add_vector does not specify the insertion location.

Can you please elaborate a bit this line?

Shekharrajak avatar Apr 21 '19 13:04 Shekharrajak

This is good point.

we can add another column easily but then we have to order it. You can also do df[:player] = df.index but yeah we should have a method to insert a column in specific place. may be we can have #insert method having information about index of column, vector name and vector value.

Shekharrajak avatar Apr 21 '19 14:04 Shekharrajak

That's exactly what I wanted to say.

kojix2 avatar Apr 22 '19 05:04 kojix2

Thanks for letting us know this usecase.

Shekharrajak avatar Apr 22 '19 06:04 Shekharrajak

Hello @Shekharrajak , I would like to work on this one.

cyrillefr avatar Dec 20 '19 12:12 cyrillefr

@cyrillefr , please go ahead. You can discuss your approach here once so that we can verify that you are going in right way then you can open a PR.

Shekharrajak avatar Dec 20 '19 12:12 Shekharrajak

Hello @Shekharrajak , sorry for the little delay. My idea is : add some new data at the end, then reorder. The method would look like this: def insert_vector n, name, sourcevector = Daru::Vector.new(source, index: @index, name: @name)@data << vector@vectors = @vectors.add nameordr = @vectors.dup.to_aelmnt = ordr.popordr = ordr.insert n, elmntself.order=ordr end

cyrillefr avatar Mar 08 '20 18:03 cyrillefr

Thanks @cyrillefr , please go ahead open a PR with few corner test cases. Love to see the changes in new release :)

Shekharrajak avatar Mar 09 '20 05:03 Shekharrajak