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?
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With