0

I'm using python3 and pandas I need to replace my file slashes from "" TO "/"

df = pandas.read_csv(file)

df2 = df.drop(columns=['Name'])
df2 = df2[['MD5', 'FullName']]

df2.replace(to_replace="\\", value="/")

The above seems like it should work but its not replacing anything? - also the only column I really need to have this replaced in is 'FullName' if thats possible.

Tony
  • 8,681
  • 7
  • 36
  • 55
  • 3
    `df2['FullName'] = df2['FullName'].str.replace("\\","/")` ? related doc: https://pandas.pydata.org/docs/reference/api/pandas.Series.str.replace.html – anky Aug 24 '21 at 16:49
  • @anky. Please reopen the question, the problem is with escape backslash not how to use the `replace` method. – Corralien Aug 24 '21 at 17:29
  • @Corralien thanks, it is actually both and the solution I suggested in my comments should work , if you refer `also the only column I really need to have this replaced in is 'FullName' if thats possible` it asks for str.replace. added the dupe for backlash too – anky Aug 24 '21 at 17:35
  • @anky. I'm agree `but its not replacing anything` (probably) mean there is a problem with `'\\'`. – Corralien Aug 24 '21 at 17:37
  • OK... All the questions in StackOverflow on Pandas should be close because if you merge all answers you will always get the right solution :-) – Corralien Aug 24 '21 at 17:39
  • @Corralien Nope, I only closed this question because OP specially asked for a single column for which the solution I suggested works with the same pattern which OP had. Also I am not merging any answers, the single answer in the comment works with OP's pattern – anky Aug 24 '21 at 17:42

0 Answers0