Python CSV file reader : bad cells format for high numbers
Question: I'm using the csv file reader of python to read a csv file. My code is the
following :

    
    
    with open(self.csv_file, 'rb') as csvfile:
            data = list(csv.reader(csvfile, delimiter=';'))
    

Everything works fine except for one column of my csv file. I have columns
with float numbers that are between 1 and -1 (ex : 0,34430203959) and it works
perfectly but one of my column is dealing with very high numbers (ex :
142266963436).Because the cells of the file are formatted as "standards", my
CSV file is printig the number 142266963436 as 142.266.963.436 (as shown in
the figure below) :

![enter image description here](http://i.stack.imgur.com/53uha.jpg)

There is the problem. When I parse my CSV file, he has no problems dealing
with little numbers because there is only one "." but when I parse high
numbers with a lot of "." python interpret them as "float" and put the "."
after the fist number.

So, instead of having the number :

    
    
    142266963436
    

I have the number :

    
    
    1.42266963436
    

Anyone has an idea of how i could fix this ?

Thanks for your help !


Answer: Your CSV file contains that oddity; it looks as if all your `z` columns are
afflicted (`ankle_pos.z` and `toe_pos.z` in your screenshot). If you are
certain these values are meant to be floats then you can use Python to
'repair' these:

    
    
    import csv
    
    def repaired_float(c):
        try:
            return float(c)
        except ValueError:
            # interpret ddd.ddd.ddd.ddd as 0.ddddddddd instead
            return float('.{}'.format(c.replace('.', ''))
    
    with open(filename, 'rb') as infh:
        reader = csv.reader(infh)
        next(reader, None)  # skip header row
        for row in reader:
            row = map(repaired_float, row)
            # do something with row 
    

If you wanted to interpret those values as (large) integers, replace the last
2 lines in `repaired_float()` with:

    
    
    # interpret ddd.ddd.ddd.ddd as ddddddddd instead
    return int(c.replace('.', ''))
    

