Tag Archives: pd.to_csv Error

pd.to_csv Error: need to escape, but no escapechar set

pd.to_ In the case of CSV,

df3.to_csv('E:\\data\\xxxx.csv',index=False,header= 0,sep='|', encoding="utf-8", quoting=csv.QUOTE_NONE)

Error: need to escape, but no escape set

Reason: this problem may be because the description contains’ | ‘,’ | ‘is also a separator, and the CSV tries to escape it, but it can’t, because there is no separator csv.escapechars set up

Solution:
provide an escape char when quoting is quote_ When none, specify a character so that it is not restricted by the separator for escape.

df3.to_csv('E:\\data\\xxxx.csv',index=False,header= 0,sep='|', encoding="utf-8", quoting=csv.QUOTE_NONE,escapechar='|')

Reference:
https://stackoverflow.com/questions/32107790/writing-to-csv-getting-error-need-to-escape-for-a-blank-string