Question
PLEASE USE PYTHON In this project you will develop tools for performing sentiment analysis on a database of tweets from across the country. When the
PLEASE USE PYTHON
In this project you will develop tools for performing sentiment analysis on a database of tweets from across the country. When the project is complete you should be able to estimate the sentiment of tweets filtered by content.
There are 4 files provided here: http://www.cs.columbia.edu/~cannon/tweet_data/
all_tweets.txt is the large collection of tweets
some_tweets.txt is a subset of all_tweets that's more manageable to prototype on
sentiments.csv a csv with word sentiment values
zips.csv (not required, see below)
We will go over the format of each of these files in class.
Tweets: We will represent a tweet using a Python dictionary with the following entries:
text: a string, the text of the tweet all in lowercase
time: a datetime object, date and time of the tweet
latitude: a float, the latitude of the tweet's location
longitude: a float, the longitude of the tweet's location
Problem 2 Write a function add_sentiment to determine the sentiment of each tweet by taking the average sentiment over all of the words in the tweet. The function should return a new list of tweets where each tweet has a new key 'sentiment' with numeric value between -1 and 1, or None representing the sentiment of the tweet. Note: words without a sentiment do not have sentiment 0. Your function should take as input a list of tweets (dictionaries) together with the name of the sentiment file. Be careful that your function does not alter the original list (no side effects!)
In [ ]:
def add_sentiment(tweets,filename): #your code here
Problem 4 Use your work above and below to answer the following questions:
What is the average sentiment of tweets containing the word 'beer'
What is the average sentiment of tweets containing the word 'coffee'
Consider the average sentiment of the tweets containing at lesast one of the words 'beer', 'movie','coffee', 'work'. Which word leads to a list of tweets with the lowest average sentiment?
In [ ]:
# Include the code you wrote for Problem 4 here
Write the answers to problem 4 here:
Average sentiment:
Average sentiment:
Lowest average sentiment:
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started