I currently have a Pandas DataFrame that contains many backslashes used in escape characters. For example, there are strings that are of the form 'Michael\'s dog'
.
When I save this DataFrame to a CSV file using pandas.DataFrame.to_csv
, I would like to get rid of these backslashes so that the entry in the CSV file would simply be "Michael's dog"
.
Is there a simply way that I can do this, either by taking advantage of a function or method? I've attempted to go through the original DataFrame and make the changes manually but I can't shake off the feeling that there must be a more efficient way.
Thank you.
Edit
Sorry for the confusion, perhaps I should have been more specific in my original question.
The data that I'm having trouble with is of the form:
[' [\'Mazda\', \'it\', "Mazda \'s", \'its\', \'its\', "Mazda \'s"]',
" ['the 2019 Mazda3', 'the 2019 Mazda3', 'it', 'the 2019 Mazda3', 'The 2019 Mazda3', 'its']",
" ['the car', 'its']",
' [\'the Japanese automaker\', "the brand \'s"]']
As you can see, the data is technically a list and not a string, which means that simply using replace
won't work.