osdir.com


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Reading 'scientific' csv using Pandas?


On 2018-11-19 21:32, Martin Sch??n wrote:
> Den 2018-11-19 skrev Martin Sch??n <martin.schoon at gmail.com>:
>> Den 2018-11-19 skrev Peter Otten <__peter__ at web.de>:
>>>
>>> The engine="python" produces an exception over here:
>>>
>>> """
>>> ValueError: The 'decimal' option is not supported with the 'python' engine
>>> """
>>>
>>> Maybe you can try and omit that option?
>>
>> Bingo!
>> No, I don't remember why I added that engine thing. It was two days ago!
>>
>>> If that doesn't work you can specify a converter:
>>>
>>>>>> pd.read_csv("file.csv", sep="\t", converters={0: lambda s: 
>>> float(s.replace(",", "."))})
>>>            col1  col2
>>> 0  1.100000e+00     0
>>> 1  1.024000e-04     1
>>> 2  9.492000e-10     2
>>>
>>> [3 rows x 2 columns]
>>
> I spoke too early. Upon closer inspection I get the first column with
> decimal '.' and the rest with decimal ','. I have tried the converter
> thing to no avail :-(
> 
You passed {0: lambda s: float(s.replace(",", "."))} as the converters 
argument, which means that it applies only to column 0.