我在清洁推文时遇到问题。我有一个将推文保存在csv中的过程,然后对数据做一个pandas数据框。

x是我的数据帧中的一条推文:

'b\'RT @LBC: James O\\\'Brien on Geoffrey Cox\\\'s awaited legal advice: "We are waiting for a single unelected expert to tell us whether or not fore\\xe2\\x80\\xa6\''

更多推文:
"b'RT @suzannelynch1: Meanwhile in #Washington... Almost two dozen members of #Congress write to #TheresaMay on eve of #StPatricksDay visit wa\\xe2\\x80\\xa6'

b"RT @KMTV_Kent: #KentTonight Poll:\\nKent\'s MPs will be having their say on Theresa May\'s #Brexit deal today. @SirRogerGaleMP said he\'ll back\\xe2\\x80\\xa6"

结果应如下所示:
James O'Brien on Geoffrey Cox's awaited legal advice: "We are waiting for a single unelected expert to tell us whether or not for'
(保留标签,只删除任何utf8字符)

我想清除此推文。我试图将regex与re.sub(my_regex),re.compile一起使用...

我尝试过的正则表达式不同:([\ U00010000- \ U0010ffff],r'@ [A-Za-z0-9] +',https?:// [A-Za-z0-9./] +)

我也这样尝试过:

x.encode('ascii','ignore').decode('utf-8')


由于双反斜杠它不起作用,当我这样做时起作用:

'to tell us whether or not fore\xe2\x80\xa6'.encode('ascii','ignore').decode('utf-8')


它返回我:

'to tell us whether or not fore'


有人知道如何清洁吗?
非常感谢 !

最佳答案

看看这是否有帮助

a = 'b\'RT @LBC: James O\\\'Brien on Geoffrey Cox\\\'s awaited legal advice:     "We are waiting for a single unelected expert to tell us whether or not fore\\xe2\\x80\\xa6\''

chars = re.findall("""[\s"'#]+\w+""",a)

''.join([c for c in chars if c])


输出量

James O'Brien on Geoffrey Cox's awaited legal advice: "We are waiting for a single unelected expert to tell us whether or not for'

关于python - 清洁推文的问题(表情符号,表情符号...),我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/55241606/

10-13 01:19