0

I am new to ruby and trying to use it's csv libary.

The first thing i tried was just to write a simple script:

require "csv"
average_money_spent = Array.new
CSV.foreach('customers.csv', converters: :numeric) do |row|
  average_money_spent << row[2] / row[1]
end

This gave the error message: Unclosed quoted field on line 1. So then i tried the exact same thing but require 'csv'. I got this error message: Unclosed quoted field on line 1.

I thought it may be to do with not having CSV gems installed on my ruby so i tried : $ gem install csv

This said it could not be installed: csv requires Ruby version >= 2.5.0dev.

But i tried to install this and checked .. it isn't the latest most stable version of Ruby, the version I have is.

Is there anything I am doing wrong in the way I require csv? Thanks so much for any help. I am new to coding and Ruby.

  • 6
    Your issue has nothing to do with `require "csv"` but with your customers.csv file. Check [this](https://stackoverflow.com/questions/11548637/csv-unquoted-fields-do-not-allow-r-or-n-line-2) or post your customers.csv if that would not help. – yzalavin Jul 24 '17 at 12:40
  • 3
    Right it means "unclosed quote field on line 1" *of the CSV* – whodini9 Jul 24 '17 at 12:47

1 Answers1

2

Please check and make sure your csvfile is in the correct format.

Ning Ding
  • 92
  • 1
  • 9