I'm trying to pull different data sets from SQL into python using different lists. For example I have the following data:
years = [2006, 2007, 2008]
2006 = [A, B, C, D, E]
2007 = [D, E, F, G, H, I, J, K]
2008 = [E, F, G]
Then to pull the data in, I'm using the following formulas:
df = pd.read_sql('SELECT %s from Table' % (str(x)), con=conn)
I'd like the string, str(x), to loop through each year first, then use the list for the corresponding year.
So, first it should do 2006 and loop through the 2006 list (A, B, C, D, E), run the rest of the program, then move on to 2007 and 2008.
I've used loops before but not sure how to loop between different lists.