How to convert columns from csvfile to python orderedDict
I have a csv file and I need columns to be printed as OrderedDict
I can convert strings to orderdict using
collections.OrderedDict((row[0], row[1:]) for row in r)
in python (2.7.5)
But when I try to do the same for the columns, I get the error " cannot unpack more than one value
".
Is there a workaround?
fileLocation = 'C:/test.csv'
with open(fileLocation,'rb') as f:
r = csv.reader(f)
od = collections.OrderedDict((row[0], row[1:]) for row in r)
print od
-2
source to share