-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathtwitter.py
61 lines (43 loc) · 1.34 KB
/
twitter.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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#import numpy as np
import pandas as pd
from textblob import TextBlob
"""
def processTweet(self,tweet):
tweet = re.sub(r'\&\w*;', '', tweet)
tweet = re.sub('@[^\s]+','',tweet)
tweet = re.sub(r'\$\w*', '', tweet)
tweet = re.lower()
tweet =re.sub(r'\s\s+', ' ', tweet)
tweet = re.lstrip(' ')
return ''.join(c for c in tweet if c <= '\uFFFF')
"""
dataset=pd.read_csv('twitter.csv' , engine='python')
x=dataset.iloc[:,5]
#df=pd.DataFrame(columns=[6])
pos=0
neg=0
neu=0
y=0
for tweet in x:
y=y+1
#tweet=processTweet(tweet)
analysis = TextBlob(tweet)
if analysis.sentiment.polarity > 0:
# dataset[x, 7]=1
pos=pos+1
# ptweets= [ tweet for tweet in x if analysis.sentiment.polarity > 0]
# df=df.apend(1)
elif analysis.sentiment.polarity == 0:
# neutweets= [ tweet for tweet in x if analysis.sentiment.polarity == 0]
neu=neu+1
else:
# dataset[x, 7]=-1
# ntweets= [ tweet for tweet in x if analysis.sentiment.polarity <-1 ]
neg=neg+1
# df=df.apend(-1)
print("percentage of positive tweets")
print(pos*100/y)
print("percentage of negative tweets")
print(neg*100/y)
print("percentage of neutral tweets")
print(neu*100/y)