Python: difficult in converting csv to list of list
Question: I want to read a .csv file which has data format like

    
    
    -179.750  71.250   -26.7   -19.5   -22.5   -22.3    -8.0    -0.6     2.5 
    -179.750  68.750   -28.5   -21.3   -24.4   -24.4    -8.0     0.0     4.0
    .....
    

and I want to convert to list of list as

    
    
    [[-179.750,71.250..2.5],[-179.750,68.750,..4.0]
    

I use csv module to read csv file as:

    
    
     import csv
     csvfile= open('test.csv','rU')
     reader = csv.reader(csvfile,quotechar=" ")
     allRows = list(reader)
     print allRows
    

The output is

    
    
    [['-179.750  68.750 ... -26.5'],['-179.750  68.250 ... 4.0']]
    

please give me some idea so that i can modify and get my output. Thanks.


Answer: The `quotechar` argument is for the character to be used to enclose a data
entry containing delimiters, etc. You should use `delimiter`.

If you want numbers out, not lists of strings, you'll want to also put the
results through `float`.

    
    
    import csv
    csvfile= open('test.csv','rU')
    reader = csv.reader(csvfile,delimiter=" ")
    allRows = list(reader)
    print allRows
    
    numData=[ [float(i) for i in row]
              for row in allRows]
    
    print numData
    

