CSV new-line character seen in unquoted field error

后端 未结 9 1221
花落未央
花落未央 2020-11-27 14:14

the following code worked until today when I imported from a Windows machine and got this error:

new-line character seen in unquoted field - do you need to o

相关标签:
9条回答
  • 2020-11-27 14:38

    This is an error that I faced. I had saved .csv file in MAC OSX.

    While saving, save it as "Windows Comma Separated Values (.csv)" which resolved the issue.

    0 讨论(0)
  • 2020-11-27 14:42

    For Mac OS X, save your CSV file in "Windows Comma Separated (.csv)" format.

    0 讨论(0)
  • 2020-11-27 14:45

    I know this has been answered for quite some time but not solve my problem. I am using DictReader and StringIO for my csv reading due to some other complications. I was able to solve problem more simply by replacing delimiters explicitly:

    with urllib.request.urlopen(q) as response:
        raw_data = response.read()
        encoding = response.info().get_content_charset('utf8') 
        data = raw_data.decode(encoding)
        if '\r\n' not in data:
            # proably a windows delimited thing...try to update it
            data = data.replace('\r', '\r\n')
    

    Might not be reasonable for enormous CSV files, but worked well for my use case.

    0 讨论(0)
提交回复
热议问题