[英]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_list
的tweet
對象沒有text
屬性。 確保數據符合您的預期
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.