'Continue Python sql inserting when it fails
I try to insert data into MySQL using Python:
#loop through the data frame
for i,row in df_.iterrows():
#here %S means string values
sql = "INSERT INTO mydb.test VALUES (%s,%s)"
cursor.execute(sql, tuple(row))
print("Record inserted")
# the connection is not auto committed by default, so we must commit to save our changes
link.commit()
Since it's a quite large dataset, there are various problems that could lead an error, e.g. the length of some data is too large to insert, or it contains NaN. What should one modify to skip the error and finish the loop? (Ignore those that could lead an error.)
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
