Practical Exercises
Fantastic! You've just navigated through an intricate but fascinating case study on social media sentiment analysis. Now it's time to get your hands dirty with some practical exercises that will solidify your understanding. Grab your keyboard and let's get started!
Exercise 1: Data Collection
Collect 50 tweets containing the hashtag #Python. You can either do this manually or use an API.
Solution:
# Note: You'll need Twitter API credentials for this
import tweepy
consumer_key = 'your_consumer_key'
consumer_secret = 'your_consumer_secret'
access_token = 'your_access_token'
access_token_secret = 'your_access_token_secret'
auth = tweepy.OAuthHandler(consumer_key, consumer_secret)
auth.set_access_token(access_token, access_token_secret)
api = tweepy.API(auth)
tweets = api.search(q='#Python', count=50)
for tweet in tweets:
print(tweet.text)