Feb-03-2019, 07:40 AM
Hi All,
My python code is not working in the 'for' loop.
I am trying to save all the data from csv file to mysql database and want to save every row starting from the first row to the last row.
Thanks.
<python>
try:
for index, col in hdbrpi.iterrows():
quarter = col[0]
index = col[1]
data = {
'quarter': quarter,
'index' : index
}
query = ("INSERT INTO table_hdbrpi(quarter, index)"
"VALUES(%(quarter)s, %(index)s")
cursor.execute(query, data)
print("Adding row " + str(index))
cnx.commit()
print("All data inserted!")
except:
print("Unexpected error:", sys.exc_info()[0])
exit()
finally:
cursor.close()
cnx.close()
</python>
My python code is not working in the 'for' loop.
I am trying to save all the data from csv file to mysql database and want to save every row starting from the first row to the last row.
Thanks.
<python>
try:
for index, col in hdbrpi.iterrows():
quarter = col[0]
index = col[1]
data = {
'quarter': quarter,
'index' : index
}
query = ("INSERT INTO table_hdbrpi(quarter, index)"
"VALUES(%(quarter)s, %(index)s")
cursor.execute(query, data)
print("Adding row " + str(index))
cnx.commit()
print("All data inserted!")
except:
print("Unexpected error:", sys.exc_info()[0])
exit()
finally:
cursor.close()
cnx.close()
</python>