python pandas read_csv quotechar does not work

后端 未结 2 1058
借酒劲吻你
借酒劲吻你 2020-12-18 06:21

I\'ve read this, this and this posts but despite I don\'t know why quotechar does not work at pd.read_csv() (Python 3, pandas 0.18.0 and 0.18.1). A

相关标签:
2条回答
  • 2020-12-18 07:14

    Another solution is to use a proper regular expression instead of the simple \s+. We need to find comma (,) which is not within quotation marks:

    pd.read_csv(file, 
                sep=', (?=(?:"[^"]*?(?: [^"]*)*))|, (?=[^",]+(?:,|$))',
                engine='python')
    

    The expression is taken from here.

    0 讨论(0)
  • 2020-12-18 07:15

    Pandas doc on separators in read_csv():

    Separators longer than 1 character and different from '\s+' will be interpreted as regular expressions, will force use of the python parsing engine and will ignore quotes in the data.

    Try using this instead (sep by default set to a comma):

    pd.read_csv(file, skipinitialspace = True, quotechar = '"')
    
    0 讨论(0)
提交回复
热议问题