[英]remove CR/LF in a csv file
操作系统:Windows
工具:Python
文件: https://drive.google.com/file/d/1vVhQMbnQd8qvhZ51_91_hazBc-_7pc_9/view?usp=sharing
我有一个 csv 文件,自由文本列的双引号,逗号分隔,escaping 的反斜杠。 当我使用 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)
您显然没有正确设置转义字符。 我可以毫无问题地阅读您的文件(pandas 1.2.4):
import pandas as pd
pd.read_csv("sampledata.csv", escapechar="\\").T
Output:
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
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.