[SciPy-User] Read file with comma decimal separator

Florian Lindner mailinglists@xgm...
Wed Jul 31 08:31:07 CDT 2013


Am Mittwoch, 31. Juli 2013, 15:25:56 schrieb Florian Lindner:
> Hello,
> 
> I have a file that used comma as a decimal separator. How can I read a file
> like that using loadtxt or genfromtxt ?

Since I'm not sure how many columns the file will have, I tried:

    conv = {}
    for i in range(1000):
        conv[i] = lambda a: a.replace(",", ".")

    data = np.loadtxt(f,  skiprows = 2, converters = conv)

but:

  File "/usr/lib/python2.7/site-packages/numpy/lib/npyio.py", line 817, in 
loadtxt
    converters[i] = conv
IndexError: list assignment index out of range

Regards,
Florian


More information about the SciPy-User mailing list