-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathdata-preprocessing.py
More file actions
48 lines (33 loc) · 1.12 KB
/
data-preprocessing.py
File metadata and controls
48 lines (33 loc) · 1.12 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
import json
import os
import sys
from pathlib import Path
start = 1001
def data_transformer(json_file):
data = json.load(json_file)
dict = {}
global start
lst = list(range(start, 20000))
ids = [format(x, '02d') for x in lst]
for i in range(len(data)):
del data[i]["id"]
dict[ids[i]] = data[i]
start = int(ids[i+1])
json_object = json.dumps(dict, indent=4)
result = Path(json_file.name)
path = sys.path[0] + '\\data_with_ids\\' + result.name
with open(path, "w") as outfile:
outfile.write(json_object)
return result.name
def main():
print("Starting to intialize the ids...\n")
path = sys.path[0] + '\\data'
json_files = [pos_json for pos_json in os.listdir(
path) if pos_json.endswith('.json')]
for index, js in enumerate(json_files):
with open(os.path.join(path, js)) as json_file:
name = data_transformer(json_file)
print(name + " has been successfully initialized with item ID's")
print("\nAll the files were successfully transformed.")
if __name__ == "__main__":
main()