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


1 answer


try using

od = collections.OrderedDict((row[0], row[1:]) for row in r if len(row)>1)

      



you can only have row

it withone column

0


source







All Articles