katossky commited on
Commit
6370e17
1 Parent(s): f99fa2d

add export script

Browse files

A lot more information is available in the original dataset

Files changed (1) hide show
  1. export-script.py +32 -0
export-script.py ADDED
@@ -0,0 +1,32 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import pandas as pd
2
+ from bs4 import BeautifulSoup
3
+
4
+ with open("sorted_data/books/positive.review") as file:
5
+ soup_pos = BeautifulSoup(file, "lxml")
6
+
7
+ texts_pos=[]
8
+ for review in soup_pos.find_all("review"):
9
+ texts_pos.append(review.review_text.text)
10
+
11
+ books_pos = pd.DataFrame({"text":texts_pos, "label":1})
12
+ books_pos.text = books_pos.text.replace("^\n", "", regex=True)
13
+
14
+ from sklearn.model_selection import train_test_split
15
+ books_pos_train, books_pos_test = train_test_split(books_pos, train_size=800, random_state=41)
16
+
17
+ # Not OK to sart with, OK after open+save in Sublime
18
+ # (encoding situation)
19
+ with open("sorted_data/books/negative.review") as file:
20
+ soup_neg = BeautifulSoup(file, "lxml")
21
+
22
+ texts_neg=[]
23
+ for review in soup_neg.find_all("review"):
24
+ texts_neg.append(review.review_text.text)
25
+
26
+ books_neg = pd.DataFrame({"text":texts_neg, "label":0})
27
+ books_neg.text = books_neg.text.replace("^\n", "", regex=True)
28
+
29
+ books_neg_train, books_neg_test = train_test_split(books_neg, train_size=800)
30
+
31
+ pd.concat([books_pos_train, books_neg_train]).to_csv("sorted_data/books/train.csv", index=False)
32
+ pd.concat([books_pos_test, books_neg_test ]).to_csv("sorted_data/books/test.csv", index=False)