-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLoadDatasets.py
More file actions
49 lines (36 loc) · 1.48 KB
/
LoadDatasets.py
File metadata and controls
49 lines (36 loc) · 1.48 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
import _sqlite3
import csv
def load_training_dataset():
with open('comp3208-train-small.csv', 'r') as f:
reader = csv.reader(f)
data = next(reader)
query = 'insert into Training_ts values ({0})'
query = query.format(','.join('?' * len(data)))
cursor.execute(query, data)
for data in reader:
cursor.execute(query, data)
connection.commit()
def load_testing_dataset():
with open('comp3208-test-small.csv', 'r') as f:
reader = csv.reader(f)
data = next(reader)
query = 'insert into Testing_ts values ({0})'
query = query.format(','.join('?' * len(data)))
cursor.execute(query, data)
for data in reader:
cursor.execute(query, data)
connection.commit()
connection = _sqlite3.connect("comp3208-small.db")
cursor = connection.cursor()
cursor.execute("create table Training_ts (user int, item int, rating float, timestamp int)")
load_training_dataset()
cursor.execute("create table Testing_ts (user int, item int, timestamp int)")
load_testing_dataset()
cursor.execute("create table Training (user int, item int, rating float )")
cursor.execute("insert into Training select user, item, rating from Training_ts")
cursor.execute("create table Testing (user int, item float )")
cursor.execute("insert into Testing select user, item from Testing_ts")
cursor.execute("drop table Training_ts")
cursor.execute("drop table Testing_ts")
connection.commit()
connection.close()