SciRuby / daru

Data Analysis in RUby
BSD 2-Clause "Simplified" License
1.03k stars 139 forks source link

Insert column/row into DataFrame at specified location. #507

Open kojix2 opened 5 years ago

kojix2 commented 5 years ago

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.

Shekharrajak commented 5 years ago

[]= add_vector does not specify the insertion location.

Can you please elaborate a bit this line?

Shekharrajak commented 5 years ago

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.

kojix2 commented 5 years ago

That's exactly what I wanted to say.

Shekharrajak commented 5 years ago

Thanks for letting us know this usecase.

cyrillefr commented 4 years ago

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

Shekharrajak commented 4 years ago

@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.

cyrillefr commented 4 years ago

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

Shekharrajak commented 4 years ago

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