-
Notifications
You must be signed in to change notification settings - Fork 140
Open
Description
DataFrame assignments behave in a surprising way then numerical indexes are used: instead of the vector replacing the old one, they are added to the dataframe. This is in contrast with what happen when explicit names are used.
Take for example this dataframe:
df = Daru::DataFrame.new({ :a => [1,2,3,4], :b => [5,6,7,8] })
=> #<Daru::DataFrame(4x2)>
a b
0 1 5
1 2 6
2 3 7
3 4 8Assigning df[0] will add a new vector to the dataframe instead of replacing the 0th column:
df[0] = df[0] + 10; df
=> #<Daru::DataFrame(4x3)>
a b 0
0 1 5 11
1 2 6 12
2 3 7 13
3 4 8 14This is surprising, considered that assigning to df[:a] replaces the :a column as expected:
df[:a] = df[:a] + 10; df
=> #<Daru::DataFrame(4x2)>
a b
0 11 5
1 12 6
2 13 7
3 14 8and that df[:a] and df[0] both return the same vector
df[:a]
=> #<Daru::Vector(4)>
a
0 1
1 2
2 3
3 4df[0]
=> #<Daru::Vector(4)>
a
0 1
1 2
2 3
3 4Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels