Upload 2 files
Browse files- convert.py +19 -7
- polarity.csv +2 -2
convert.py
CHANGED
@@ -1,8 +1,12 @@
|
|
1 |
import csv
|
2 |
import random
|
3 |
|
|
|
|
|
4 |
import pandas as pd
|
5 |
|
|
|
|
|
6 |
|
7 |
def remap_polarity(row):
|
8 |
if row["label"] < 2:
|
@@ -15,15 +19,23 @@ def remap_polarity(row):
|
|
15 |
def run():
|
16 |
rows = []
|
17 |
|
18 |
-
with open(
|
19 |
-
|
20 |
-
|
21 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
22 |
for row in reader:
|
23 |
-
|
|
|
|
|
24 |
|
25 |
df = pd.DataFrame(rows)
|
26 |
-
df.to_csv("complete.csv", index=False)
|
27 |
|
28 |
polarity_rows = [remap_polarity(row) for row in rows if row["label"] != 2]
|
29 |
positive_rows = [row for row in polarity_rows if row["label"] == 1]
|
@@ -34,7 +46,7 @@ def run():
|
|
34 |
random.shuffle(polarity_rows)
|
35 |
|
36 |
df = pd.DataFrame(polarity_rows)
|
37 |
-
df.to_csv("polarity.csv", index=False)
|
38 |
|
39 |
|
40 |
if __name__ == "__main__":
|
|
|
1 |
import csv
|
2 |
import random
|
3 |
|
4 |
+
from io import StringIO
|
5 |
+
|
6 |
import pandas as pd
|
7 |
|
8 |
+
from bs4 import BeautifulSoup
|
9 |
+
|
10 |
|
11 |
def remap_polarity(row):
|
12 |
if row["label"] < 2:
|
|
|
19 |
def run():
|
20 |
rows = []
|
21 |
|
22 |
+
with open("training.1600000.processed.noemoticon.csv", "rb") as file:
|
23 |
+
lines = [line[:-1] for line in file.readlines()]
|
24 |
+
|
25 |
+
for line in lines:
|
26 |
+
try:
|
27 |
+
data = StringIO(line.decode("utf-8"))
|
28 |
+
except UnicodeDecodeError:
|
29 |
+
data = StringIO(line.decode("latin-1", errors="ignore"))
|
30 |
+
|
31 |
+
reader = csv.reader(data, delimiter=",")
|
32 |
for row in reader:
|
33 |
+
bs = BeautifulSoup(row[5], "lxml")
|
34 |
+
obj = {"label": int(row[0]), "text": bs.get_text()}
|
35 |
+
rows.append(obj)
|
36 |
|
37 |
df = pd.DataFrame(rows)
|
38 |
+
df.to_csv("complete.csv", index=False, encoding="utf-8")
|
39 |
|
40 |
polarity_rows = [remap_polarity(row) for row in rows if row["label"] != 2]
|
41 |
positive_rows = [row for row in polarity_rows if row["label"] == 1]
|
|
|
46 |
random.shuffle(polarity_rows)
|
47 |
|
48 |
df = pd.DataFrame(polarity_rows)
|
49 |
+
df.to_csv("polarity.csv", index=False, encoding="utf8")
|
50 |
|
51 |
|
52 |
if __name__ == "__main__":
|
polarity.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:5c661cd1bb47f9c74eb29e8792f8ed6243c409887d80ab9e0c8ad1486c1f925a
|
3 |
+
size 123635617
|