Python 带双引号的 csv 在列中不分隔

Python csv with double quotes doesnt separate in column

我在读取 python 中的 csv 文件时遇到一些问题 我有我的数据,但有些列里面有双引号,例如:

First field First Row,This is the second field in the first row
First Field Second Row,This is the "second" field in the second row

所以,我的 csv reader 如下:

with open('data.csv', encoding="utf-8") as csv_file:
csv_reader = csv.reader(csv_file, delimiter=',')

问题是,当我遍历行时​​,当它检查第二行时,出于某种原因它不会拆分“,”上的列。 所以当我打印每一行时我得到这个:

['First field First Row' , 'This is the second field in the first row']
['First Field Second Row,This is the "second" field in the second row']

有任何修复可以正确拆分吗?

提前致谢!

默认情况下,双引号是特殊的,用于引用字段。您必须告诉 reader 它们在您的文件中并不特殊:

with open('data.csv', encoding="utf-8") as csv_file:
    csv_reader = csv.reader(csv_file, delimiter=',', quoting=csv.QUOTE_NONE)