-
Notifications
You must be signed in to change notification settings - Fork 0
/
visualproject.py
37 lines (31 loc) · 921 Bytes
/
visualproject.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
'''
In this project, you will visualize the feelings and language used in a set of
Tweets. This starter code loads the appropriate libraries and the Twitter data you'll
need!
'''
import json
from textblob import TextBlob
import matplotlib.pyplot as plt
#Get the JSON data
tweetFile = open("tweets.json", "r")
tweetData = json.load(tweetFile)
tweetFile.close()
polarity_values = []
for tweet in tweetData:
tweet_text = tweet["text"]
tb = TextBlob(tweet["text"])
print("{}: {}". format(tweet_text, tb.polarity))
polarity_values.append(tb.polarity)
bins = [-1, -0.5, 0, 0.5, 1]
plt.hist(polarity_values)
plt.title("Tweet Polarity")
plt.ylabel("Count of tweets")
plt.xlabel("Polarity")
plt.grid()
plt.show()
# Continue your program below!
# Textblob sample:
# while True:
# phrase = input("Enter a phrase: ")
# tb = TextBlob(phrase)
# print(tb.polarity)