Morpheu5 Morpheu5 - 25 days ago 4x
Ruby Question

How do I address Daru Vectors in a DataFrame using symbols rather than strings?

I see this happening in a lot of online code examples, but when I parse my CSV file, all I get are strings as column indices, like

> data = Daru::DataFrame.from_csv('my_fancy_data.csv')
> data[:user_id]
IndexError: Specified index :user_id does not exist

> data['user_id']
=> #<Daru::Vector(42815)>
0 z0udgxc0lusu1gr4xj65
1 28080
2 28080
... ...

data = Daru::DataFrame.from_csv('my_fancy_data.csv', headers: true, header_converters: :symbol)

From the documentation:

You can specify all the options to the .from_csv function that you do to the Ruby function, since this is what is used internally.