-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathget_graph_data.py
More file actions
68 lines (41 loc) · 1.67 KB
/
get_graph_data.py
File metadata and controls
68 lines (41 loc) · 1.67 KB
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
63
64
import csv
import string
positive_count = 0
negative_count = 0
neutral_count = 0
score_counts = {1:0, 2:0, 3:0, 4:0, 5:0}
word_dictionary_count = {}
# Read CSV and replace any non-utf-8 charactes with "?"
with open ('csv_files/Equal_unmodified.csv','r', errors='replace') as csv_file:
reader = csv.reader(csv_file)
next(reader) # Skip the row that contains the column names.
for row in reader:
product_name = row[0]
product_price = row[1]
product_rating_number = row[2]
product_review_short_message = row[3]
product_review_short_summary = row[4]
product_sentiment = row[5]
combined_text = product_review_short_message + " " + product_review_short_summary
combined_text = combined_text.translate(str.maketrans('', '', string.punctuation)).lower()
if(len(product_rating_number) > 1):
# invalid data
continue
if product_sentiment == "positive":
positive_count += 1
elif product_sentiment == "negative":
negative_count += 1
elif product_sentiment == "neutral":
neutral_count += 1
score_counts[int(product_rating_number)] += 1
# Count words for word cloud.
for word in combined_text.split(" "):
if word in word_dictionary_count:
word_dictionary_count[word] += 1
else:
word_dictionary_count[word] = 1
print("Positive count: " + str(positive_count))
print("Negative count: " + str(negative_count))
print("Neutral count: " + str(neutral_count))
print("Score Counts: " + str(score_counts))
print(word_dictionary_count)