gpt4 book ai didi

AttributeError: module 'emoji' has no attribute 'get_emoji_regexp'(AttributeError:模块‘emoji’没有属性‘get_emoji_regexp’)

转载 作者:bug小助手 更新时间:2023-10-26 20:24:23 57 4
gpt4 key购买 nike



This is the code I'm using in Google Colab

这是我在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)

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?

这很奇怪。我以前从来没有见过这个问题。有没有人能帮我一下?我是不是做错了什么?


更多回答

What part of the error message is unclear? Where the code says emoji.get_emoji_regexp().sub(u'', text), why should this mean anything? In particular, why should the emoji.get_emoji_regexp part mean anything? The error message is telling you, very explicitly, that there is no get_emoji_regexp to be found within emoji. Do you think there should be? If so, why? What does the documentation say?

错误消息的哪部分不清楚?其中代码是emoji.get_emoji_regexp().Sub(u‘’,Text),这意味着什么?特别是,为什么emoji.get_emoji_regexp部分应该有任何意义?错误消息非常明确地告诉您,在emoji中找不到get_emoji_regexp。你觉得应该有吗?如果是,原因何在?文档是怎么说的?

@KarlKnechtel this is my college project. When my profesor runs this in his local anoconda env, it is ok, but why not in colab?

@KarlKnechtel这是我的大学项目。当我的开发者在他的本地anoconda env中运行这个时,这是可以的,但为什么不是在colab中呢?

优秀答案推荐

For anyone looking for an up-to-date solution,
pip install demoji, then try this function instead:

对于任何寻求最新解决方案的人,请通过pip安装demoji,然后尝试此功能:


def remove_emojis(text):
return demoji.replace(text, '')


AttributeError: module 'emoji' has no attribute 'get_emoji_regexp' - get_emoji_regexp method was deprecated and subsequently removed in new versions of the package.

属性错误:模块“emoji”没有属性“get_emoji_regexp”- get_emoji_regexp方法已弃用,随后在新版本的软件包中被删除。



Uninstall the current version you have and use version 1.4.1

卸载您拥有的当前版本并使用版本1.4.1


pip install emoji==1.4.1

PIP安装表情==1.4.1


更多回答

Your answer could be improved with additional supporting information. Please edit to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers in the help center.

您的答案可以通过其他支持信息来改进。请编辑以添加更多详细信息,如引用或文档,以便其他人可以确认您的答案是正确的。你可以在帮助中心找到更多关于如何写出好答案的信息。

57 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com