The Python Oracle

Removing backslashes from values in a Pandas dataframe

--------------------------------------------------
Rise to the top 3% as a developer or hire one of them at Toptal: https://topt.al/25cXVn
--------------------------------------------------

Music by Eric Matyas
https://www.soundimage.org
Track title: Puzzle Game 3 Looping

--

Chapters
00:00 Removing Backslashes From Values In A Pandas Dataframe
00:33 Answer 1 Score 0
00:44 Accepted Answer Score 12
00:52 Thank you

--

Full question
https://stackoverflow.com/questions/5286...

--

Content licensed under CC BY-SA
https://meta.stackexchange.com/help/lice...

--

Tags
#python #pandas #dataframe #replace #escaping

#avk47



ACCEPTED ANSWER

Score 12


You can use replace

df = df.replace(to_replace= r'\\', value= '', regex=True)



ANSWER 2

Score 0


I prefer to use the string API for each column.

for col in df:
    df[col] = df[col].str.replace(r'\\','')