CSV read error: new-line character seen in unquoted field

前端 未结 1 2097
没有蜡笔的小新
没有蜡笔的小新 2021-02-13 06:14

I created a python script which works with a test CSV dataset of 10 records. When I scaled this up to the actual datasets (a few thousand rows), I am getting the following error

相关标签:
1条回答
  • 2021-02-13 06:19

    From PEP-0278:

    In a Python with universal newline support open() the mode parameter can also be "U", meaning "open for input as a text file with universal newline interpretation". Mode "rU" is also allowed, for symmetry with "rb"

    So try to change

    with open('./Destinations.csv', 'r') as csvfile:
    

    to

    with open('./Destinations.csv', 'rb') as csvfile:
    

    If the error persists, change to

    with open('./Destinations.csv', 'rU') as csvfile:
    

    Edited accorded to Martijn Pieters's comment.

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