Closed info-rchitect closed 7 years ago
You can simply add new vectors to a DataFrame by specifying a new vector name and assigning an Array or Vector using =
.
2.3.3 :006 > a=Daru::DataFrame.new({a: [1,2,3], b: [2,3,4]})
=> #<Daru::DataFrame(3x2)>
a b
0 1 2
1 2 3
2 3 4
2.3.3 :007 > a[:c] = [3,4,5]
=> [3, 4, 5]
2.3.3 :008 > a
=> #<Daru::DataFrame(3x3)>
a b c
0 1 2 3
1 2 3 4
2 3 4 5
If you assign a Vector to a[:c]
it will match the indexes with the dataframe and then create the new vector.
The only constraint is that when you assign an Array
the length of the array should be equal to the column size of the dataframe.
thx
Hi,
Wonder what people think about allowing Vector method_missing to interrogate the values within it via respond_to? and if so then execute the method. The use case for me is adding new columns to a DataFrame.
In the case above it is just getting a substring of Vector with strings in it. How do folks handle this now?
thx