"Medical Center Emergency Physicians \"North Shore\" Houston, TX EM MD-DO",2680,18882
I want it to be read in as length 3 list use python csv module this my expected output
["Medical Center Emergency Physicians \"North Shore\" Houston, TX EM MD-DO",
'2680',
18882]
I have tried a lot use different parameter. But all the below I tried doesn't work for me. All of them output a length 4 list. I think this is caused by the comma after Huston. But how can we ignore it since it is in a double quote?
csv_reader = csv.reader(f, doublequote=True, quoting=csv.QUOTE_ALL)
csv_reader = csv.reader(f, doublequote=False, quoting=csv.QUOTE_ALL)
csv_reader = csv.reader(f, doublequote=False)
csv_reader = csv.reader(f, doublequote=True)
csv_reader = csv.reader(f)
Just add an escape character to deal with escaped quotes in the csv
csv.reader(f, doublequote=True, quoting=csv.QUOTE_ALL, escapechar='\\')
You'll have to use:
csv.reader(f, quotechar='"')
and possibly some parameter to tell the reader the quotes are escaped with \. But if your current output is 4 fields, it seems to split on the ,, ignoring the \".
Most likely like this:
csv.reader(f, quotechar='"', escapechar='\\')
Those \ shouldn't be in your output (unless you need them for further processing).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With