jeudi 10 juin 2021

Want to run a query multiple times using a for loop and add each result into a dictionary. This code only execute once even as it loops through

I have a query that take a random sample of records. I want to do this multiple times and add each result into a dictionary, which I will concat into a pandas DataFrame later. This code only execute once even as it loops through.

cursor.execute("select record1, record2 from table order by random() limit 1000")

d = {}
for x in range(10):
    d[x] = pd.DataFrame(cursor.fetchall())



Aucun commentaire:

Enregistrer un commentaire