I have a list of values created from some analysis I did on Pandas. I then want to run a for loop to execute a SQL query using each of the values in that list.
I'd like these results to either be appended to a new DataFrame- I can initialise previously, or to add each one to a new DataFrame, which I can then append myself.
Example code is below, where df['a'] would be the results column of my previous analysis.
df = pd.DataFrame(np.array([[1, 2, 3], [4, 5, 6], [7, 8, 9]]),
columns=['a', 'b', 'c'])
x = df['a']
r = pd.DataFrame(columns=['F', 'G', 'H', 'I'])
for m in x:
r.append(pd.read_sql_query("""SELECT a.F,a.G,a.H,a.I
FROM users a
WHERE a.F ="""+m,engine))
I'd like all the the data to append to r