【发布时间】:2022-08-06 21:42:41
【问题描述】:
我在 Excel 中有一个 CSV 文件,类似于此示例:
Name,Age,Shoe_Size,Motto
David,29,41.5,\"If you\'re going through hell, keep going.\"
Amy,23,38,Seize the day
如果我用文本编辑器打开这个文件,它会显示如下:
Name,Age,Shoe_Size,Motto
\"David,29,41.5,\"\"If you\'re going through hell, keep going.\"\"\"
Amy,23,38,Seize the day
也就是说,第一行作为一个字符串处理。当我尝试在 Python 中阅读时也是如此,所以我得到了这个错误的输出:
Name Age Shoe_Size Motto
1 David,29,41.5,\"If you\'re going through hell, keep going.\" NA NA NA
2 Amy 23 38 Seize the day
也就是说,第一行中的所有内容都放在第一列中。但是,输出应如下所示:
Name Age Shoe_Size Motto
1 David 29 41.5 If you\'re going through hell, keep going.
2 Amy 23 38 Seize the day
如何解决第一行和已经双引号的部分放在双引号中的问题,以便我得到我想要的输出?
非常感谢!
标签: python csv double-quotes