Python csv to list TypeError: cannot perform reduce with flexible type
Question: I am trying to get my test.csv file that looks like this:  
hr,mime,active  
100,0.41,1  
101,0.19,1  
102,0.18,1  
103,0.6,1  
104,0.45,1  
105,0.7,1  
90,0.4,1  
72.43,0.17,1  
73,0.17,1  
110,0.5,1  
120,1,1  
130,2,1  
72.19,0.5,1  
72.68,0.5,1  

To look like this:

    
    
    data = ((100, 0.4, 1), (101, 0.19, 1), (102, 0.18, 1), (103, 0.4, 1),
            (104, 0.4, 1), (105, 0.4, 1), (90, 0.4, 1), (72.43, 0.17, 1),
            (73, 0.17, 1), (110, 0.5, 1), (120, 0.17, 1), (130, 0.18, 1),
            (72.19, 0.5, 1), (72.68, 0.5, 1))
    

I've tried the following:

    
    
    import csv
    with open('test.csv', 'rb') as f:
        reader = csv.reader(f)
        data = map(tuple, reader)
    

But when it is printed it looks like this:

    
    
    [('hr', 'mime', 'active'), ('100', '0.41', '1'), ('101', '0.19', '1'), ('102', '0.18', '1'), ('103', '0.6', '1'), ('104', '0.45', '1'), ('105', '0.7', '1'), ('90', '0.4', '1'), ('72.43', '0.17', '1'), ('73', '0.17', '1'), ('110', '0.5', '1'), ('120', '1', '1'), ('130', '2', '1'), ('72.19', '0.5', '1'), ('72.68', '0.5', '1')]
    

Also when I try to run some code with hr I get this error:

    
    
    TypeError: cannot perform reduce with flexible type
    

What am I doing incorrectly?


Answer: This should work:

    
    
    import csv
    
    def convert(line):
        return tuple(map(float, line))
    
    with open('test.csv', 'rb') as f:
        reader = tuple(csv.reader(f))[1:]
        data = tuple(map(convert, reader))
    

