File tree 2 files changed +26
-0
lines changed
2 files changed +26
-0
lines changed Original file line number Diff line number Diff line change 4
4
import codecs #provides transparent encoding/decoding
5
5
from textblob import TextBlob #Library for Text Processing
6
6
import time
7
+ from collections import Counter
7
8
8
9
#Plotting dependecies
9
10
import matplotlib .pyplot as plt ; plt .rcdefaults ()
16
17
neutral = 0
17
18
total = 0
18
19
20
+ hashtags = []
21
+
19
22
#Loading.....
20
23
print ("Performing Sentiment Analysis" ,end = "" )
21
24
for i in range (5 ):
85
88
file .write (tweet )
86
89
file .write ('<br><br>\n ' )
87
90
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 ())
88
100
89
101
#Plotting data
90
102
112
124
plt .axis ('equal' )
113
125
plt .title ('Twitter Sentiment Analysis- Demonetisation (Pie Chart) \n ' )
114
126
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 ()
You can’t perform that action at this time.
0 commit comments