You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
escapechar : str (length 1), default None
One-character string used to escape delimiter when quoting is QUOTE_NONE.
But in reality you can correctly parse following CSV:
id, name
1, "Hello, my name is \"John\""
using this code:
importpandasaspddf=pd.read_csv("john.csv", quotechar='"', escapechar="\\")
print(df.name) # prints Hello, my name is "John"print(df.id) # prints 1
Also same doc states that default quoting is QUOTE_MINIMAL, not QUOTE_NONE in example above.
Trying same with quoting=csv.QUOTE_NONE will give you incorrect result:
importpandasaspdimportcsvdf=pd.read_csv("john.csv", quotechar='"', escapechar="\\", quoting=csv.QUOTE_NONE)
print(df.name) # prints my name is John""print(df.id) # prints 1, "Hello
Trying same without escapechar will also give you incorrect result:
importpandasaspddf=pd.read_csv("john.csv", quotechar='"')
print(df.name) # prints Hello, my name is \John\""print(df.id) # prints 1
Looks like doc is misleading here, incorrectly stating that escapechar is used only for QUOTE_NONE when in fact it can be used with default mode (maybe as result of some bugfixes?)
The text was updated successfully, but these errors were encountered:
@frenzykryger : Thanks for reporting this! Indeed, the documentation on escapechar can be much improved and should really be more generic in being just an "escape character" (and not as tied to the quoting parameter). PR is more than welcome!
Problem description
Documentation of pandas.read_csv states:
But in reality you can correctly parse following CSV:
using this code:
Also same doc states that default quoting is QUOTE_MINIMAL, not QUOTE_NONE in example above.
Trying same with quoting=csv.QUOTE_NONE will give you incorrect result:
Trying same without escapechar will also give you incorrect result:
Looks like doc is misleading here, incorrectly stating that escapechar is used only for QUOTE_NONE when in fact it can be used with default mode (maybe as result of some bugfixes?)
The text was updated successfully, but these errors were encountered: