-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathjsontosqlite.py
More file actions
35 lines (29 loc) · 926 Bytes
/
jsontosqlite.py
File metadata and controls
35 lines (29 loc) · 926 Bytes
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
import json
import sqlite3
conn=sqlite3.connect('patientdata.sqlite')
cur=conn.cursor()
fname='asdf.txt'
strdata = open(fname).read()
data = json.loads(strdata)
cur.executescript('''
DROP TABLE IF EXISTS Records;
CREATE TABLE Records(
age INTEGER,
sex INTEGER,
cp INTEGER,
trestbps INTEGER,
chol INTEGER,
fbs INTEGER,
restecg INTEGER,
thalach INTEGER,
exang INTEGER,
oldpeak INTEGER,
slope INTEGER,
ca INTEGER,
thal INTEGER
)
''')
for i in data['records']:
cur.execute('INSERT INTO Records (age,sex,cp,trestbps,chol,fbs,restecg,thalach,exang,oldpeak,slope,ca,thal) VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?)',(i['age'],i['sex'],i['cp'],i['trestbps'],i['chol'],i['fbs'],i['restecg'],i['thalach'],i['exang'],i['oldpeak'],i['slope'],i['ca'],i['thal']))
conn.commit()
conn.close()