-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSenti.py
More file actions
34 lines (26 loc) · 765 Bytes
/
Senti.py
File metadata and controls
34 lines (26 loc) · 765 Bytes
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
from textblob import TextBlob
#ANALYSING SENTIMENT AND RATING THEM FROM -1 TO +1
def analyse_sentiment(df , term):
f_list=df[term].to_list()
pol=list()
for l in f_list:
analysis=TextBlob(l).sentiment
t=analysis.polarity
pol.append(t)
df['sentiment']=pol
pol2=list()
for l in pol:
if(l>0):
pol2.append("Positive")
elif(l<0):
pol2.append("Negative")
else:
pol2.append("Neutral")
df['roundoff']=pol2
df=df[df.sentiment != 0]
return df
def pretty_txt(input_value):
input_value = input_value.replace(" ", "")
input_value = input_value.replace("-", "")
input_value = input_value.replace("[^a-zA-Z#]", " ")
return (input_value)