Hello. I have a lot of .csv files in a directory and I'd like to open each of them in a loop within Python such that the first .csv is read into list[0] and the second .csv is read into list[1] and so on. Here's my code:
EDIT: see code in attached .jpg
def create_data_lists():
i=0
for symbol in symbols:
with open(symbols+'.csv', 'r') as f:
print i
reader = csv.reader(f)
reader.next()
for row in reader:
rowdata.append(row)
data_by_symbol.append(rowdata)
i=i+1
Unfortunately, while the code loops through all of the .csv files, it puts all the .csv files into list[0]. How can I modify my code so that I can achieve my goal above? Many thanks.
John
EDIT: see code in attached .jpg
def create_data_lists():
i=0
for symbol in symbols:
with open(symbols+'.csv', 'r') as f:
print i
reader = csv.reader(f)
reader.next()
for row in reader:
rowdata.append(row)
data_by_symbol.append(rowdata)
i=i+1
Unfortunately, while the code loops through all of the .csv files, it puts all the .csv files into list[0]. How can I modify my code so that I can achieve my goal above? Many thanks.
John
Attachments
Last edited: