Reputation: 97
I am trying to convert a column to int, so i don't have 0 in front of the number and .0 after the number. this is what i am using
data['ID'] = pd.to_numeric(data['ID'], errors='coerce')
but it is not converting the column type
here is image what it looks like.
Please if you can help
Upvotes: 2
Views: 310
Reputation: 260380
This is due to the NaNs that are of float type.
You can use fillna
to make the NaNs 0:
data['ID'] = pd.to_numeric(data['ID'], errors='coerce').fillna(0, downcast='infer')
Or to keep the NaN as the new integer NA, use convert_dtypes
:
data['ID'] = pd.to_numeric(data['ID'], errors='coerce').convert_dtypes()
Upvotes: 1