Python 推特情绪分析错误代码:KeyError:';文本';

Python 推特情绪分析错误代码:KeyError:';文本';,python,Python,我正在尝试使用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:

我正在尝试使用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'
文件“”,第1行,在
text_only_list=[tweet[“text”]用于tweets_list中的tweet]
文件“”,第1行,在
text_only_list=[tweet[“text”]用于tweets_list中的tweet]
KeyError:“文本”

这仅仅意味着
tweet\u列表中的
tweet
对象没有
text
属性。确保数据看起来与您期望的一样

我用于获取此错误的代码是:text_only_list=[tweet[“text”]用于tweets中的tweet_list]new_list=[]用于text中的text_only_list:text=text.translate(table)text=text.lower()new_list.append(text)请将该信息编辑到原始问题中。您可以使用
dir(tweet)
查看属性,使用
tweet.keys()
查看字典的键。显然
“text”
不在这些键中。