[SciPy-User] Read file with comma decimal separator
Pierre Gerard-Marchant
pgmdevlist at gmail.com
Wed Jul 31 09:40:43 EDT 2013
On Jul 31, 2013, at 15:31 , Florian Lindner <mailinglists at xgm.de> wrote:
> 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 ?
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)
>>>np.genfromtxt(replaced, delimiter="\t")
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
mailing list