0

I'm attempting to create a map using Python and the beautiful soup library.

I am a newbie and am inexperienced with programming.

I am receiving the attached error and am unsure how to proceed. Presumably there is an issue with my data file (a csv file).

What is Python telling me? What does "new line character in unquoted field" mean?

Here is the code:

# Read in script rates
scriptrate = {}
min_value = 100; max_value = 0
reader = csv.reader(open('/users/gcameron/Desktop/map/data.csv'), delimiter=",")
for row in reader:
try:
 county = row[1] 
 rate = float( row[2].strip() )
 rate[county] = rate
except:
 pass

enter image description here

asked Oct 21, 2012 at 19:14
3
  • This is your third question of the day? Commented Oct 21, 2012 at 19:14
  • 1
    Did you screw up your formatting or did you forget to indent all the code inside the for loop? Because right now that for is empty. Commented Oct 21, 2012 at 19:15
  • maybee its an option you are missing in csv.reader Commented Oct 21, 2012 at 19:15

2 Answers 2

2

The error message says that it's something with your file, and the problem is on this line.

reader = csv.reader(open('/users/gcameron/Desktop/map/data.csv'), delimiter=",")

It says you need to change to:

reader = csv.reader(open('/users/gcameron/Desktop/map/data.csv', 'rU'), delimiter=",")

Notice the 'rU', it tells python to read the file in universal newline mode, as said in the error message. I am not sure this will help, but you should try it.

You should also attach your csv file, as I believe the problem lies in the file if the above method doesn't work.

answered Oct 21, 2012 at 19:16
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks for all your help today xiaomao
0

This problem occurs because of the different new line formats in different operating systems. Python, by default, assumes new-lines to be Unix style LF (\n) and if this is not the case then you have a problem.

In your case, your .csv may have very well come from Windows and hence all excel quirks(formatting issues). You can fix it by opening in universal new-line mode. Change: open(r'/users/gcameron/Desktop/map/data.csv', 'rU')

answered Oct 21, 2012 at 19:21

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.