简体   繁体   English

Twitter 情绪分析错误代码:KeyError: 'text'

[英]Twitter sentiment analysis error code: KeyError: 'text'

I am trying to run a twitter sentiment analysis using AFINN in python.我正在尝试在 python 中使用 AFINN 运行 twitter 情绪分析。 here is the section of code I am having trouble with:这是我遇到问题的代码部分:

# Create a list of the tweets ("text") only
text_only_list = [tweet["text"] for tweet in tweets_list]
# Remove digit and punctuation, and convert to lower case
new_list = []
for text in text_only_list:
    text = text.translate(table)
    text = text.lower()
    new_list.append(text)

And here is the error code I am receiving:这是我收到的错误代码:

  File "<ipython-input-3-731d7bbe9420>", line 1, in <module>
    text_only_list = [tweet["text"] for tweet in tweets_list]

  File "<ipython-input-3-731d7bbe9420>", line 1, in <listcomp>
    text_only_list = [tweet["text"] for tweet in tweets_list]

KeyError: 'text'

This simply means the tweet objects in tweet_list don't have a text attribute.这只是意味着tweet_listtweet对象没有text属性。 Make sure the data looks like what you expect确保数据符合您的预期

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM