Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does float' object has no attribute 'replace' when I try locale.atof in Pandas?

Tags:

python

pandas

I'm trying to convert a Pandas dataframe series to float. I do locale.setlocale(locale.LC_NUMERIC, '') and then df.idh.apply(locale.atof), but it gives me the above mentioned error: AttributeError: 'float' object has no attribute 'replace'. I assume at some point it's getting something like a NaN, maybe or some other string and it does not recognize it. How do I tell apply to skip those?

like image 392
Dervin Thunk Avatar asked Aug 26 '15 21:08

Dervin Thunk


1 Answers

Well, I don't know how "smart" this is, but I "fixed" it like this, at least for the time being:

df.idh = df.idh.astype(str).apply(locale.atof)

Please, do let me know the smart answer to this.

like image 182
Dervin Thunk Avatar answered Nov 14 '22 23:11

Dervin Thunk