Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Python by (120 points)

Hi..I want to copy the data from table 1 to the table 2. So, I have created a button to start insert the data. The problem is I got this error MySQLdb._exceptions.ProgrammingError: not enough arguments for format string.

This is my code:

cur.execute("INSERT INTO table2 (id,q) WHERE id = %s SELECT id,q FROM table1 WHERE id = %s", [id])

Hope u can help me

1 Answer

0 votes
by (36.8k points)
edited by

The line for the row in df: does NOT iterate over a row as you intended, it rather iterates over each column's names (row will be of type str and hold the name of a column in this case).

Rather look into the methods .iterrows().itertuples() or .iteritems().

For example (code from your docs I linked above):

for label, content in df.iteritems():

    print('label:', label)

    print('content:', content)

Want to gain end-to-end skills in Data Science with Python? Enroll today in this Data Science with Python Course and be a master in it

Browse Categories

...