Pandas read_csv do not interprete quotechar

Home / python / Pandas read_csv do not interprete quotechar

Question:
Using the following CSV file:"aa"!#"2811"!#"Location"!#"11"!#"67000"!#"ZZ"
"bb"!#2812!#"Location"!#"22"!#"67540"!#"XX"
"cc"!#"2813"!#Location!#"33"!#"67117"!#"YY"
"dd"!#"2452"!#"location"!#"44"!#"67000"!#"ZZ"
And using the following python code :import pandas
import csv
pandas.read_csv("test.csv", sep="!#", header=None, quotechar=’"’)
Give the following result:0 0 1 2 3 4 5
0 "aa" "2811" "Location" "11" "67000" "ZZ"
1 "bb" 2812 "Location" "22" "67540" "XX"
2 "cc" "2813" Location "33" "67117" "YY"
3 "dd" "2452" "location" "44" "67000" "ZZ"
However, as I specified quotechar=’"’, the result should be
0 1 2 3 4 5
0 aa 2811 Location 11 67000 ZZ
1 bb 2812 Location 22 67540 XX
2 cc 2813 Location 33 67117 YY
3 dd 2452 location 44 67000 ZZ
Am I missing anything ?

Edit: Replacing all !# by , makes it work, so apparently, quotechar isn’t interpreted as sep is more than 1 char. So I’m looking for a solution without any str.replace() (I can’t change the !#, and " are important as !# can be found within a column.


Answer:
Please see here: python pandas read_csv quotechar does not work

The quotechar does not work if the separator is more than one character. I tried with a comma as a separator and it works.
Read more

Leave a Reply

Your email address will not be published. Required fields are marked *