Reputation: 239
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 .
I tried
csvfiledf.to_csv(outputcsv, index=False, sep='\",\"')
but get
TypeError: "delimiter" must be a 1-character string
Upvotes: 1
Views: 9093
Reputation: 164623
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.
Upvotes: 6