-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlanguage_check.py
More file actions
47 lines (40 loc) · 1.69 KB
/
language_check.py
File metadata and controls
47 lines (40 loc) · 1.69 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
import json
# File name
file_name = "steam_reviews_2778580.json"
# Load the JSON data
with open(file_name, 'r', encoding='utf-8') as file:
data = json.load(file)
# Dictionary to store counts of positive and negative reviews per language
review_counts = {}
# Initialize counts for each language
for review_id, review_data in data.items():
if isinstance(review_data, dict): # Check if review_data is a dictionary
language = review_data.get("language", "")
if language not in review_counts:
review_counts[language] = {
"positive": 0,
"negative": 0
}
# Process each review
for review_id, review_data in data.items():
if isinstance(review_data, dict): # Check if review_data is a dictionary
language = review_data.get("language", "")
voted_up = review_data.get("voted_up", None)
if voted_up is not None:
if voted_up:
review_counts[language]["positive"] += 1
else:
review_counts[language]["negative"] += 1
# Output the results
for language, counts in review_counts.items():
total_reviews = counts["positive"] + counts["negative"]
print(f"Language: {language}")
print(f" Positive Reviews: {counts['positive']}")
print(f" Negative Reviews: {counts['negative']}")
print(f" Total Reviews: {total_reviews}")
if total_reviews > 0:
percentage_positive = (counts["positive"] / total_reviews) * 100
percentage_negative = (counts["negative"] / total_reviews) * 100
print(f" Percentage Positive Reviews: {percentage_positive:.2f}%")
print(f" Percentage Negative Reviews: {percentage_negative:.2f}%")
print()