Datasets:
1T Conte
commited on
Commit
•
aec9efa
1
Parent(s):
574299f
fix: positive and negative ratings to 0 or 1
Browse files- convert.py +10 -2
- positive_negative.csv +2 -2
- positive_negative_balanced.csv +2 -2
convert.py
CHANGED
@@ -48,6 +48,14 @@ def read_file(file_path):
|
|
48 |
return rows
|
49 |
|
50 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
51 |
def save(rows, file_path):
|
52 |
df = pd.DataFrame(rows)
|
53 |
df.to_csv(file_path, index=False)
|
@@ -64,8 +72,8 @@ def run():
|
|
64 |
|
65 |
# Extract only ratings 1, 2, 3, and 4 (negative reviews), and also
|
66 |
# ratings 7, 8, 9, and 10 (positive reviews)
|
67 |
-
negative_rows = [row for row in all_rows if row["rating"] <= 4]
|
68 |
-
positive_rows = [row for row in all_rows if row["rating"] >= 7]
|
69 |
positive_negative_rows = negative_rows + positive_rows
|
70 |
shuffle(positive_negative_rows)
|
71 |
save(positive_negative_rows, "positive_negative.csv")
|
|
|
48 |
return rows
|
49 |
|
50 |
|
51 |
+
def remap2sentiment(row):
|
52 |
+
if row["rating"] <= 4:
|
53 |
+
row["rating"] = 0
|
54 |
+
else:
|
55 |
+
row["rating"] = 1
|
56 |
+
return row
|
57 |
+
|
58 |
+
|
59 |
def save(rows, file_path):
|
60 |
df = pd.DataFrame(rows)
|
61 |
df.to_csv(file_path, index=False)
|
|
|
72 |
|
73 |
# Extract only ratings 1, 2, 3, and 4 (negative reviews), and also
|
74 |
# ratings 7, 8, 9, and 10 (positive reviews)
|
75 |
+
negative_rows = [remap2sentiment(row) for row in all_rows if row["rating"] <= 4]
|
76 |
+
positive_rows = [remap2sentiment(row) for row in all_rows if row["rating"] >= 7]
|
77 |
positive_negative_rows = negative_rows + positive_rows
|
78 |
shuffle(positive_negative_rows)
|
79 |
save(positive_negative_rows, "positive_negative.csv")
|
positive_negative.csv
CHANGED
@@ -1,3 +1,3 @@
|
|
1 |
version https://git-lfs.github.com/spec/v1
|
2 |
-
oid sha256:
|
3 |
-
size
|
|
|
1 |
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:79bc54b2e84c261a9f2870b6094fef66b6c3f6f0dee3472121548e1eabcf4f04
|
3 |
+
size 97800610
|
positive_negative_balanced.csv
CHANGED
@@ -1,3 +1,3 @@
|
|
1 |
version https://git-lfs.github.com/spec/v1
|
2 |
-
oid sha256:
|
3 |
-
size
|
|
|
1 |
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:a2f57a99c1f62054fe0df39cd677d2178b3cf842d31a11d599abc173c0c1a787
|
3 |
+
size 53025847
|