Open gioele opened 5 years ago
Hello. I am a Daru beginner too. Therefore, perhaps I may be wrong, but I will reply.
I used Daru enthusiastically for the past two weeks, I noticed that Daru has two different principles from Pandas.
Daru is not a matrix calculation library. Dataframes focuses on manipulating the series by name. The importance of naming is a part of Ruby's culture.
You should access vectors by index name.
df["name_of_vector"]
or column number
df.at(1)
Row You can access rows by index name.
df.row["name_of_row"]
or row number
df.row_at(1)
Somehow df[column_number]
df.row[row_number]
work too.
But they are not recommend way. #[](*names)
method is for names. Not for column number.
This may be the reasons for this strange behavior you wrote.
df = Daru::DataFrame.new({ :a => [1,2,3,4], :b => [5,6,7,8] })
df.set_at [0], (df.at(0) + 10)
df
Probably this is the correct way of writing, but I feel like being told that "Do not call Vector by the number of columns"
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:
Assigning
df[0]
will add a new vector to the dataframe instead of replacing the 0th column:This is surprising, considered that assigning to
df[:a]
replaces the:a
column as expected:and that
df[:a]
anddf[0]
both return the same vector