1

I need to import a huge csv data file (6880 columns) and I need to be able use the column headers to access it.

What's the best way?

Speed isn't important. Clarity is.

srboisvert
  • 12,679
  • 15
  • 63
  • 87

1 Answers1

7

FasterCSV (also available as CSV in Ruby 1.9 standard library) should be able to do the trick. You can use column headers to access a row's data:

require 'fastercsv'
FasterCSV.foreach(csv_file, {:headers => true, :return_headers => false, :header_converters => :symbol, :converters => :all} ) do |row|
    puts row[:some_column_header] # Would be "Some Column Header" in the csv file.
end 
Community
  • 1
  • 1
Hates_
  • 66,613
  • 6
  • 32
  • 37