pandas :使用带有引号和逗号作为分隔符的to_csv() [英] Pandas: use to_csv() with quotation marks and a comma as a seperator
本文介绍了 pandas :使用带有引号和逗号作为分隔符的to_csv()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我是熊猫的新手,在导出到另一系统的正确CSV格式时遇到问题。
I'm new to pandas, and I'm having trouble exporting to the correct CSV format for another system.
源文件看起来像这样,其中的字段由引号和逗号。
Source file looks like this with fields seperated by a quotation marks and a comma.
"User ID","Description","User Name"
"user1","John","john01"
"user2","Mike","mike33"
"user3","Barry","barry66"
我想以相同的格式导出,但是我无法导出。
I want to export in the same format but I am unable to .
我尝试了
csvfiledf.to_csv(outputcsv, index=False, sep='\",\"')
但得到
TypeError: "delimiter" must be a 1-character string
推荐答案
输出文件中的分隔符仍为,
。您需要修改的是 quoting
参数:
The delimiter in your output file is still ,
. What you need to modify is the quoting
argument:
import csv
csvfiledf.to_csv(outputcsv, index=False, delimiter=',', quoting=csv.QUOTE_ALL)
分隔符
参数是可选的,因为暗示了,
。
The delimiter
argument is optional, since ,
is implied.
这篇关于 pandas :使用带有引号和逗号作为分隔符的to_csv()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文