1

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
jpp
  • 159,742
  • 34
  • 281
  • 339
Jacksporrow
  • 239
  • 5
  • 10

1 Answers1

4

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.

mit
  • 11,083
  • 11
  • 50
  • 74
jpp
  • 159,742
  • 34
  • 281
  • 339
  • 1
    I got this working thanks, but the quoting parameter was an integer and not a boolean - e.g. `quoting=csv.QUOTE_ALL` – Jacksporrow Apr 28 '18 at 22:15