I have a sqlite database with the below columns, and 1000 rows
con.execute('CREATE TABLE "table" (Fruit TEXT, Texture TEXT, Code TEXT, Buy TEXT )'
I want to compare a pandas.Dataframe
with this table
, and if the value in the column sqlite "Code"
is not in df['Code']
, then update sqlite "Buy"
with the word "Yes".
Initially I tried using the below code to see if I can get all the results from df['Code']
to print if it exists, then I could just add in a NOT
into the sqlite query
to flip the results, but currently, the below code prints out 1000 rows of empty lists, and occasionally prints out some of the Code
instead...
for each_code in df['Code']:
z = con.execute('SELECT EXISTS(SELECT 1 FROM "table" WHERE Code IN ({c}))'
.format(c=each_code)).fetchall()
print(z)
Not sure where my error lies? I thought of doing this at the database level since it might be faster.