I am trying to run a twitter sentiment analysis using AFINN in python. 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. Make sure the data looks like what you expect
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.