-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcsv_to_mysql.py
30 lines (24 loc) · 867 Bytes
/
csv_to_mysql.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
import csv
import mysql.connector
mydb = mysql.connector.connect(host="localhost", user="root", passwd="1234", db="disease_spv")
cursor = mydb.cursor()
with open('clean_db.csv', 'r') as csvfile:
csv_data = csv.reader(csvfile)
csv_headings = next(csv_data)
for row in csv_data:
# print(row)
cursor.execute('INSERT INTO diseasetb (disease, \
symptom1, symptom2, symptom3, symptom4, symptom5, symptom6 )' \
'VALUES(%s, %s, %s, %s, %s, %s, %s)',
row)
with open('Symptom-severity.csv', 'r') as csvfile:
csv_data = csv.reader(csvfile)
csv_headings = next(csv_data)
for row in csv_data:
cursor.execute('INSERT INTO symptomtb (symptom, weight)' \
'VALUES(%s, %s)',
row)
#close the connection to the database.
mydb.commit()
cursor.close()
print("Done")