I have a table that looks like the following:
|A|B|C|D|
|---|---|---|---|
|1|b1|c1|d1|
|1|b2|c2|d2|
|2|b3|c3|d3|
|2|b4|c4|d4|
I would like to iterate over distinct values of A and build a pandas data frame out of the remaining columns and then use that table to do calculations. I tried the following:
import sqlite3
import pandas as pd
conn = sqlite3.connection('my_db.db')
c = conn.cursor()
for entry in c.execute("SELECT DISTINCT A in table):
df = pd.DataFrame(c.execute("SELECT * FROM table WHERE A = ?", (entry[0],)).fetchall())
This doesn't work because the second cursor object that builds the dataframe overwrites the cursor object that i was iterating over. I also discovered that you can not have two cursor objects. How should I work around this?