我搜索了一段时间,但找不到一些有用的东西。我尝试在Paython列表中的字符串中删除这些十六进制代码,但不知道该怎么做。他们采用字符串格式!除了我的数据(特朗普Twitter获取(:
tweets[7]
'rt @ lindseygrahamsc : i support president trump\xe2\x80\x99s desire to reenter the paris accord after the agreement becomes a better deal for america\xe2\x80\xa6'
谢谢!
尝试这种方式,它仅适用于子字符串' \x**
':
import re
tweets = 'rt @ lindseygrahamsc : i support president trump\xe2\x80\x99s desire to reenter the paris accord after the agreement becomes a better deal for america\xe2\x80\xa6'
re.sub(r'(\x(.){2})', '',tweets)
输出:
'rt @ lindseygrahamsc : i support president trumps desire to reenter the paris accord after the agreement becomes a better deal for america'