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?
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?
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('\\', '')