-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathReviews_analysis.py
62 lines (49 loc) · 1.57 KB
/
Reviews_analysis.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
62
# import pandas as pd
# from nltk.sentiment.vader import SentimentIntensityAnalyzer
# from nltk import tokenize
# import csv
# import matplotlib.pyplot as plt
# import nltk
# #nltk.download('vader_lexicon')
# data = pd.read_csv('C:/Users/mayank/Desktop/reviews_1.csv')
# Comments = data['ReviewText'].head(100)
# sid = SentimentIntensityAnalyzer()
# w = csv.writer(open("Comments.csv", "w", encoding = 'utf-8', newline = ''))
# count = 1
# for comment in Comments:
# if count == 1:
# w.writerow(['Comment', 'pos', 'neg', 'neu'])
# count += 1
# else:
# ss = sid.polarity_scores(comment)
# values = []
# for key,value in ss.items():
# values.append((value))
# w.writerow([comment, values[2], values[0], values[1]])
import pandas as pd
from nltk.sentiment.vader import SentimentIntensityAnalyzer
from nltk import tokenize
import csv
import matplotlib.pyplot as plt
import nltk
#nltk.download('vader_lexicon')
data = pd.read_csv('C:/Users/mayank/Desktop/reviews_1.csv')
Comments = data['ReviewText'].head(100)
print(Comments)
sid = SentimentIntensityAnalyzer()
w = csv.writer(open("Comments.csv", "a", newline = ''))
count = 1
for comment in Comments:
if count == 1:
w.writerow(['Comment', 'pos', 'neg', 'neu'])
count += 1
else:
if(str(comment) != 'nan'):
ss = sid.polarity_scores(comment)
values = []
for key,value in ss.items():
values.append((value))
w.writerow([comment, values[2], values[0], values[1]])
# for i in Comments:
# if (str(i) != 'nan'):
# print((i))