这是我在 Google Colab 中使用的代码
import re
from textblob import TextBlob
import emoji
def clean_tweet(text):
text = re.sub(r'@[A-Za-z0-9]+', '', str(text)) # remove @mentions
text = re.sub(r'#', '', str(text)) # remove the '#' symbol
text = re.sub(r'RT[\s]+', '', str(text)) # remove RT
text = re.sub(r'https?\/\/S+', '', str(text)) # remove the hyperlink
text = re.sub(r'http\S+', '', str(text)) # remove the hyperlink
text = re.sub(r'www\S+', '', str(text)) # remove the www
text = re.sub(r'twitter+', '', str(text)) # remove the twitter
text = re.sub(r'pic+', '', str(text)) # remove the pic
text = re.sub(r'com', '', str(text)) # remove the com
return text
def remove_emoji(text):
return emoji.get_emoji_regexp().sub(u'', text)
当我拨打这些电话时
tweets['cleaned_text']=tweets['text'].apply(clean_tweet)
tweets['cleaned_text']=tweets['cleaned_text'].apply(remove_emoji)
我收到以下错误
AttributeError Traceback (most recent call last)
<ipython-input-20-9fe71f3cdb0c> in <module>
1 tweets['cleaned_text']=tweets['text'].apply(clean_tweet)
----> 2 tweets['cleaned_text']=tweets['cleaned_text'].apply(remove_emoji)
4 frames
<ipython-input-19-8c0d6ba00a5b> in remove_emoji(text)
24
25 def remove_emoji(text):
---> 26 return emoji.get_emoji_regexp().sub(u'', text)
AttributeError: module 'emoji' has no attribute 'get_emoji_regexp'
这很奇怪。我以前从未见过这个问题。有人可以帮我解决这个问题吗?我在这里做错了什么吗?
AttributeError:模块“emoji”没有属性“get_emoji_regexp” -
get_emoji_regexp
方法已被弃用,随后在新版本的包中被删除。
对于任何寻求最新解决方案的人来说,
pip install demoji
,那就试试这个功能吧:
def remove_emojis(text):
return demoji.replace(text, '')
卸载当前版本并使用版本1.4.1
pip 安装表情符号==1.4.1