【问题标题】:CSV file in Excel with double quotes due to commas由于逗号,Excel 中的 CSV 文件带有双引号
【发布时间】: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


    【解决方案1】:

    当您从 Excel 导出到 CSV 时,您可以选择指定每一列被 " 包围(以修复初始问题..导出)

    这样您就可以正确解析python pandas ..

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-09-28
      • 2019-03-28
      • 2014-04-22
      • 1970-01-01
      • 2016-03-18
      • 1970-01-01
      • 1970-01-01
      • 2014-02-26
      相关资源
      最近更新 更多