0

I would like to read some gz files by pandas, in which data are split by '', in python 3.
If I use the code:

pd.read_csv('my file.gz',sep='\')

I will get the error "EOL while scanning string literal".
What is the correct way to do this?

0

2 Answers 2

0

The backslash is an escape character. You must escape it sep='\\'.

Sign up to request clarification or add additional context in comments.

Comments

0
pd.read_csv('my file.gz',sep='\\') # use \\ instead of \

Sometimes csv file uses a specific separator, such as \t (TAB), instead of a comma(,). In this case, if the csv file use \ as a separator, you have to use \\ instead of \ because \ is an escape character.

There are many other special characters that require escape character \, such as \t (TAB), \\ (BACKSLASH), and \ (Single Quote).

You can see more information about ESCAPE here: https://www.w3schools.com/python/gloss_python_escape_characters.asp

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.