forked from ChrisLiu95/Cancer-prediction
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathparse_file_case_id.py
47 lines (28 loc) · 913 Bytes
/
parse_file_case_id.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
#copyright: [email protected]
import pandas as pd
import json
from multiprocessing import Pool
def processFile(inputfile,outputfile):
'''
read the json file and parse the file id and case id info and save it
'''
with open(inputfile) as data_file:
data = json.load(data_file)
data_arr = []
case_ids = set()
for each_record in data:
# print (each_record)
file_id = each_record['file_id']
case_id = each_record['cases'][0]['case_id']
if case_id in case_ids:
case_ids.add(case_id)
else:
data_arr.append([file_id,case_id])
df = pd.DataFrame(data_arr, columns = ['file_id','case_id'])
df.to_csv(outputfile,index=False)
if __name__ == '__main__':
# modify the input file path when use it.
data_dir = "/Users/Tony/Desktop/tmp/"
inputFile = data_dir + "files.OtherType.json"
outputFile = data_dir + 'file_case_OtherType.csv'
processFile(inputFile, outputFile)