sql - Looping between different lists in python -
i'm trying pull different data sets sql python using different lists. example have 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 pull data in, i'm using following formulas:
df = pd.read_sql('select %s table' % (str(x)), con=conn) i'd string, str(x), loop through each year first, use list corresponding year.
so, first should 2006 , loop through 2006 list (a, b, c, d, e), run rest of program, move on 2007 , 2008.
i've used loops before not sure how loop between different lists.
if understand correctly, might want express data hierarchically:
years = { 2006: ['a', 'b', 'c', 'd', 'e'], 2007: ['d', 'e', 'f', 'g', 'h', 'i', 'j', 'k'], 2008: ['e', 'f', 'g'], } you loop on years , on letters each year this:
for year, letters in years.items(): # per year letter in letters: # per letter year does answer question?
Comments
Post a Comment