我的.csv文件如下:
col1, col2, col3, col4, col5, col6
"a, """"b, ""string1"""""", ""string2, string3"", """", c,"
"d, """"e, ""string4"""""", ""string5, string6"", """", f,"
我想用熊猫读取此文件。如何在一个read_csv命令中应对这三个挑战?
答案 0 :(得分:0)
您可以使用str.replace
并在双引号后面加上一个空的str。
>>> x = '"d, """"e, ""string4"""""", ""string5, string6""'
>>> x
'"d, """"e, ""string4"""""", ""string5, string6""'
>>> x.replace('"', '')
'd, e, string4, string5, string6'
要修复csv文件...
name = 'xxx.csv'
with open(name) as f:
csv = f.read()
with open(name, 'w') as f:
f.write(csv.replace('"', ''))