views:

338

answers:

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.

+6  A: 

FasterCSV 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
Hates_