Skip to content

Commit a20b0ac

Browse files
committedOct 21, 2017
Hashtag Analysis Added
1 parent e4b9cad commit a20b0ac

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed
 

‎Hashtag Bar Graph.png

37.1 KB
Loading

‎analyseTweets.py

+26
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import codecs #provides transparent encoding/decoding
55
from textblob import TextBlob #Library for Text Processing
66
import time
7+
from collections import Counter
78

89
#Plotting dependecies
910
import matplotlib.pyplot as plt; plt.rcdefaults()
@@ -16,6 +17,8 @@
1617
neutral=0
1718
total=0
1819

20+
hashtags = []
21+
1922
#Loading.....
2023
print("Performing Sentiment Analysis",end="")
2124
for i in range(5):
@@ -85,6 +88,15 @@
8588
file.write(tweet)
8689
file.write('<br><br>\n')
8790

91+
#Finding the hashtags in all the tweets
92+
finalcount={}
93+
for i in tweetsList:
94+
hashtags.append(re.findall(r"#(\w+)", i))
95+
hashtagnew = [item for sub in hashtags for item in sub]
96+
counts = Counter(hashtagnew)
97+
counts = dict(counts)
98+
finalcount = dict(sorted(counts.items(), key=lambda kv: kv[1], reverse=True))
99+
countname = list(finalcount.keys())
88100

89101
#Plotting data
90102

@@ -112,3 +124,17 @@
112124
plt.axis('equal')
113125
plt.title('Twitter Sentiment Analysis- Demonetisation (Pie Chart) \n')
114126
plt.show()
127+
128+
# Hashtag Plot
129+
x = np.arange(len(finalcount))
130+
y = list(finalcount.values())
131+
x = x[:15]
132+
y = y[:15]
133+
countname = countname[:15]
134+
plt.bar(x, y)
135+
plt.title('Most Trending Hashtags\n')
136+
plt.xticks(x, countname, rotation='vertical')
137+
plt.ylabel('Number of tweets')
138+
plt.xlabel('#Hashtags')
139+
plt.tight_layout()
140+
plt.show()

0 commit comments

Comments
 (0)
Please sign in to comment.