繁体   English   中英

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

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

我正在尝试在 python 中使用 AFINN 运行 twitter 情绪分析。 这是我遇到问题的代码部分:

# 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)

这是我收到的错误代码:

  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'

这只是意味着tweet_listtweet对象没有text属性。 确保数据符合您的预期

暂无
暂无

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

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