1

I want to replace \ with blank in pandas series

df['Review'].apply(lambda x:x.replace('\','') if isinstance(x,str) else x)[0]

But this code is not working. What to change in the code?

beridzeg45
  • 246
  • 2
  • 11

1 Answers1

0

To replace the backslash character (\) with a blank space in a pandas series, you need to use double backslashes in the string ("\\") because the backslash is an escape character in Python.

df['Review'].apply(lambda x:x.replace('\\','') if isinstance(x,str) else x)[0]

Also instead of using apply function you can use the str.replace

df['Review'] = df['Review'].str.replace('\\', '')
wjandrea
  • 28,235
  • 9
  • 60
  • 81
codester_09
  • 5,622
  • 2
  • 5
  • 27