You can force it to correctly apply to a specific variable name in the data framework without having to copy it to another data format as follows:
>>> import pandas as pd >>> a = pd.DataFrame([{"letter":"a", "number":"1"},{"letter":"b", "number":"2"}]) >>> a.dtypes letter object number object dtype: object >>> a['number'] = a['number'].apply(pd.to_numeric, errors='coerce') >>> a.dtypes letter object number int64 dtype: object
An example based on the original question above would be something like this:
data['S1Q2I'] = data['S1Q2I'].apply(pd.to_numeric, errors='coerce')
This works the same as your original:
data['S1Q2I'] = data['S1Q2I'].convert_objects(convert_numeric=True)
in my hands, anyway ....
This does not apply to the paragraph of the point made about the derivation of data types that are slightly above my head. I'm afraid!
magsmanston Dec 6 '16 at 15:31 2016-12-06 15:31
source share