Python and CSV files

Joined
Nov 4, 2011
Messages
1
Reaction score
0
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
 

Attachments

  • Code.JPG
    Code.JPG
    23.4 KB · Views: 340
Last edited:

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top