Horizontal concat in Daru::DataFrame?

170 views Asked by At

I know that by Daru::DataFrame#concat one can concatenate dataframes, appending the argument df to the bottom of the caller df.

Now I want to achieve what is df.concat(other, axis=1) in Pandas. In other words, given I have two dataframes where the index are the same, append one df to the right of the other df, resulting df having same index but the concatenated vectors.

Is this possible by some method? Or do I need to iterate and add each columns in for loop?

2

There are 2 answers

1
janpeterka On

Is this what you are looking for possibly?

data_frame = data_frame.join(jobs_data_frame, how: :left, on: [:user_id])

1
Nikhil Wagh On

You can use add_vector method.

For eg:

2.6.3 :001 > require 'daru'

2.6.3 :007 > df = Daru::DataFrame.new([[00,01,02], [10,11,12],[20,21,22]], order: ["a", "b", "c"])
 => #<Daru::DataFrame(3x3)>
       a   b   c
   0   0  10  20
   1   1  11  21
   2   2  12  22
2.6.3 :008 > df.add_vector("d", [30, 31, 32])
 => [30, 31, 32]
2.6.3 :009 > df
 => #<Daru::DataFrame(3x4)>
       a   b   c   d
   0   0  10  20  30
   1   1  11  21  31
   2   2  12  22  32

Although you'll have to add each vector separately.