import csv
data = {}
f = open("train.csv")
csv_f = csv.reader(f)
labels = next(csv_f)
for i in range(len(labels-1)):
a = []
for row in csv_f:
a += row[i]
data [labels[i]] = a
I am doing the code above trying to read a csv file and put the columns into a dictionary with the first part as the labels and the second part as the arra of the values. This works for my first column, which for my data set is 'ID', but it stops working after that -- it just leaves the a
array as blank. I did some debugging and found that it was doing the outer for loop then the inner loop, but then when it did the second run through of the outer for loop, it just skipped the inner for loop. It did that for all subsequent ones also.
Why does it do that?
And how can I fix my code to make it stop?