I have tried to convert an object dtype column to float64 using .astype('float64')
It ran without raising any error, but when I check the dtype using .dtype or .dtypes it is showing that converted column again as object.
real_estate['Age at time of purchase'].astype('float64')
164 67.0 153 61.0 133 56.0 132 56.0 179 NaN ... 110 49.0 89 44.0 45 37.0 131 55.0 116 51.0 Name: Age at time of purchase, Length: 195, dtype: float64
real_estate.dtypes
Name object Surname object Age at time of purchase object Interval object Y float64 M float64 D float64 Gender object Country object State object dtype: object
Why is it not converting and why isn’t it giving any error?
also,
real_estate['Age at time of purchase'].dtype
this is giving me something that I haven’t expected. dtype('O')
What does dtype('O')
mean?
Advertisement
Answer
you can try like this
real_estate['Age at time of purchase']=real_estate['Age at time of purchase'].astype('float64')