简体   繁体   中英

Dealing with double “double quotations” in CSV

I am processing some data stored in a CSV file with python. There was a line like this:

title, tags, views, like
"Hello, world!" in python, ['beginner', 'tutorial'], '550', '540'

As you can see, there are many commas in the data which can break the CSV file. So, I enclosed all the elements with double quotations. But, there are already double quotations in the title. So, if I use a double quotation again, it just breaks the CSV file. Which look like this:

"Hello | World," in python | ['beginner', 'tutorial'] | 550 | 540

(Added " | " to make things clear)

And I want it to look like this:

"Hello, world," in python | ['beginner', 'tutorial'] | 550 | 540

How can I fix this?

Well, if you can't apply a delimiter to the commas that are not field separators...

Can you export the data with a field separating delimiter that is not in the data?

Alternately can you first convert all the commas that occur in the data to some odd character.. then export the data as a CSV file.

After importing the data into the database... or your application... run things through a function to convert the chosen odd character back to commas.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM