The following code is intended to dump a long list of numbers from a csv into stat_by_symbol[symbol] so that I can call the list of numbers using each symbol as a key. For some reason, the code only seems to work for the first symbol. Can someone help me fix the code to work as intended? Many thanks.
with open('zzdata.csv', 'rb') as f:
reader = csv.reader(f)
reader.next()
for symbol in symbols:#symbols in a list
stat = []
for row in reader:
if symbol in row:
stat.append(row[8])#stat becomes long list of numbers
stat_by_symbol[symbol] = [stat]
The problem is that you can iterate over
readerjust once (therefore just the first symbol match).Try this: