删除csv文件中的CR/LF



OS:Windows

工具:Python

文件:https://drive.google.com/file/d/1vVhQMbnQd8qvhZ51_91_hazBc-_7pc_9/view?usp=sharing

我有一个csv文件,双引号表示自由文本列,逗号分隔,反斜杠表示转义。我想,当我使用Pandas/Excel读取这个csv文件时,由于CR/LF的原因,有些行错位了。

在python中,如何删除所有cr/lf以便正确读取csv文件?我试过了,没有像预期的那样工作。

with open("sampledata.csv", "r") as infile,     
open("outfile.csv", mode="w") as outfile:     
f = infile.read()     
f = f.replace("n", " ")     
outfile.write(f)

您显然没有正确设置转义符。我可以毫无问题地阅读你的文件(熊猫1.2.4(:

import pandas as pd
pd.read_csv("sampledata.csv", escapechar="\").T

输出:

0                                                  1
Id                         a0o7F00000B6E3GQAV                                 a0o7F000007b31GQAQ
LastModifiedDate  2021-05-04 05:37:21.0000000                        2020-03-13 23:23:54.0000000
Description           Every student needs it.  We have created our "product" which is essenti...
Age                                        30                                                 25

最新更新