i am very new to mysql. i have to insert some data into the mysql table which i have already created. i have written a script to get two data and i need to insert that two data inside the 2 column of mysql table.
mysql database name is = Test1 table name is = all_data column name where i have to put value of "q" in column "query" and the value of "cnt_nas" in the column name "non_as_count" Below is my code:
import collections
import MySQLdb
queries = ['shoes','memory card','earphones','led bulb','mobile','lunch box','helmets','sunglasses','blackberry','headphones']
queries_as = ['shoes','memory card','earphones','led bulb','mobile','earphones','led bulb','mobile']
queries_non_as = ['lunch box','helmets','sunglasses','blackberry','headphones','sunglasses','blackberry','headphones']
for q in queries:
cnt_as = queries_as.count(q)
cnt_nas = queries_non_as.count(q)
ratio = (cnt_nas*100)/(cnt_as+cnt_nas)
if ratio <= 40:
print q,cnt_nas # this two i need to insert
db = MySQLdb.connect("localhost","root","*****","Test1")
cursor = db.cursor()
sql = "insert into all_data values(%s,%s)" ,(q,cnt_nas)
cursor.execute(sql)
db.commit()
db.close()
need some help.