0

I wanted to replace a string : 'li\\oa' by 'ext' but I get this error

error: octal escape value \505 outside of range 0-0o377

I know that the problem is: string containing these chracters '\\', so the question is : How can i read these backslashes as a string.

df['col']= df['col'].replace(['li\\oa'],['ext'], regex=True)
Oumab10
  • 696
  • 2
  • 6
  • 14
  • Nvm, i found the answer, you need to put '\\\\' backslashes in order for python to consider it as '\\' – Oumab10 Jul 19 '18 at 13:29

2 Answers2

1

You have to escape the two backslashes by adding one "\" for each one :

df['col']= df['col'].replace(['li\\\\oa'],['ext'], regex=True)
Eduardo Soares
  • 992
  • 4
  • 14
1

You can declare a string as raw (with an r in front of it) and it will print all its characters:

>>> string = r'li\\oa'
>>> print string
'li\\oa'

How to print backslash with Python?

SaikaVA
  • 127
  • 10