[SciPy-User] Read file with comma decimal separator
Wed Jul 31 08:40:43 CDT 2013
On Jul 31, 2013, at 15:31 , Florian Lindner <email@example.com> wrote:
> Am Mittwoch, 31. Juli 2013, 15:25:56 schrieb Florian Lindner:
>> I have a file that used comma as a decimal separator. How can I read a file
>> like that using loadtxt or genfromtxt ?
A quick and dirty approach would be to create a generator that would parse your initial input and replace the ',' by '.' on each line. You'd just have to feed the generator to `genfromtxt`:
>>>X = StringIO('1,1\t1,2\t1,3\n2,1\t2,2\t,2,3')
>>>replaced = (line.replace(",", ".") for line in X)
Of course, that'd work only if you don't intend to use "," as your delimiter, in which case you're out of luck.
More information about the SciPy-User