我的csv文件中的文本被读取为原始字符串。它包含“它”而不是它。我该如何清洁?

时间:2019-11-17 01:53:44

标签: python regex nlp sentiment-analysis rawstring

句子

'I understood that that morning did not work out for her but I would still like to to make an appointment with her. I mean if she does great lashes and it\'s just this one little hiccup in the beginning it\'s well worth it as far as I\'m concerned.'

如何删除转义字符以清除数据?

2 个答案:

答案 0 :(得分:0)

我想,一个简单的re.sub可能会起作用:

测试

import re

string = '''
I understood that that morning did not work out for her but I would still like to to make an appointment with her. I mean if she does great lashes and it\'s just this one little hiccup in the beginning it\'s well worth it as far as I\'m concerned.
'''

expression = r'\\'

print(re.sub(expression, '', string))

输出

  

我了解到那天早上对她没有帮助,但我会   仍然想和她约会。我的意思是如果她这样做   很好的睫毛,一开始只是这个小小的打cup   就我而言,这非常值得。

答案 1 :(得分:0)

正确的答案在@ bryan-oakley的评论中:没什么可做的。

作为测试:

s = 'I understood that that morning did not work out for her but I would still like to to make an appointment with her. I mean if she does great lashes and it\'s just this one little hiccup in the beginning it\'s well worth it as far as I\'m concerned.'

assert len(s) == len(s.replace('\'', "'")) # passes
assert s == s.replace('\'', "'") # passes