AttributeError: module 'emoji' has no attribute 'get_emoji_regexp'
Question:
This is the code I’m using in 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'httpS+', '', str(text)) # remove the hyperlink
text = re.sub(r'wwwS+', '', 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)
When I make these calls
tweets['cleaned_text']=tweets['text'].apply(clean_tweet)
tweets['cleaned_text']=tweets['cleaned_text'].apply(remove_emoji)
I’m getting the below error
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'
This is very strange. I have never seen this issue before. Could someone help me with this? Am I doing something wrong here?
Answers:
AttributeError: module ’emoji’ has no attribute ‘get_emoji_regexp’ – get_emoji_regexp
method was deprecated and subsequently removed in new versions of the package.
For anyone looking for an up-to-date solution,
pip install demoji
, then try this function instead:
def remove_emojis(text):
return demoji.replace(text, '')
This is the code I’m using in 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'httpS+', '', str(text)) # remove the hyperlink
text = re.sub(r'wwwS+', '', 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)
When I make these calls
tweets['cleaned_text']=tweets['text'].apply(clean_tweet)
tweets['cleaned_text']=tweets['cleaned_text'].apply(remove_emoji)
I’m getting the below error
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'
This is very strange. I have never seen this issue before. Could someone help me with this? Am I doing something wrong here?
AttributeError: module ’emoji’ has no attribute ‘get_emoji_regexp’ – get_emoji_regexp
method was deprecated and subsequently removed in new versions of the package.
For anyone looking for an up-to-date solution,
pip install demoji
, then try this function instead:
def remove_emojis(text):
return demoji.replace(text, '')