2

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)>
                       user_id
        0 z0udgxc0lusu1gr4xj65
        1                28080
        2                28080
      ...                  ...
Yuki Inoue
  • 3,569
  • 5
  • 34
  • 53
Morpheu5
  • 2,610
  • 6
  • 39
  • 72

1 Answers1

1
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 CSV.read() function, since this is what is used internally.

yenshirak
  • 3,021
  • 2
  • 21
  • 27