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

问题描述 投票:0回答:1

我在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阅读器如下:

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']

是否可以正确拆分此修补程序?

提前感谢!

python csv quote
1个回答
0
投票

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

© www.soinside.com 2019 - 2024. All rights reserved.