-
Notifications
You must be signed in to change notification settings - Fork 0
/
clean_data.py
53 lines (46 loc) · 1.53 KB
/
clean_data.py
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
50
51
52
53
import csv
from pathlib import Path
MAIN_PATH = Path("data/neo4j_db/raw_data")
files = ["Books.csv", "Users.csv", "Ratings.csv"]
if __name__ == "__main__":
for file in files:
with open(MAIN_PATH / f"{file}", 'r') as csv_file:
data = list(csv.reader(csv_file, delimiter=','))
print(f"{len(data)=}")
print(data[0])
print(data[1])
if file == "Books.csv":
data = [
(
row[0].replace('"', '').replace("\\", ""),
row[1].replace('"', '').replace("\\", ""),
row[2].replace('"', '').replace("\\", ""),
row[3],
row[4].replace('"', '').replace("\\", ""),
row[5],
row[6],
row[7]
)
for row in data
]
elif file == "Users.csv":
data = [
(
row[0],
row[1].replace('"', '').replace("\\", ""),
row[2]
)
for row in data
]
elif file == "Ratings.csv":
data = [
(
row[0],
row[1].replace('"', '').replace("\\", ""),
row[2]
)
for row in data
]
with open(MAIN_PATH / f"clean_full_{file.lower()}", 'w') as csv_file:
writer = csv.writer(csv_file, delimiter=',')
writer.writerows(data)