How can I turn a csv file into a list of list in python

Viewed 13615

I want to be able to turn csv file into a list of lists with the column values for each list. For example:

6,2,4
5,2,3
7,3,6

into

[[6,5,7],[2,2,3],[4,3,6]]

Ive only managed to open the file and only having success printing it as rows

with open(input,'rb') as csvfile:
        csv_file = csv.reader(csvfile)

        header = csv_file.next() 

        raw_data = csv_file
3 Answers

Or maybe like this...

from csv import reader   

with open('test.csv') as csv_file:
    csv_reader = reader(csv_file)
    rows = list(csv_reader)
    print(rows)
Related