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.
JavaScript
x
2
1
real_estate['Age at time of purchase'].astype('float64')
2
JavaScript
1
13
13
1
164 67.0
2
153 61.0
3
133 56.0
4
132 56.0
5
179 NaN
6
7
110 49.0
8
89 44.0
9
45 37.0
10
131 55.0
11
116 51.0
12
Name: Age at time of purchase, Length: 195, dtype: float64
13
real_estate.dtypes
JavaScript
1
12
12
1
Name object
2
Surname object
3
Age at time of purchase object
4
Interval object
5
Y float64
6
M float64
7
D float64
8
Gender object
9
Country object
10
State object
11
dtype: object
12
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
JavaScript
1
2
1
real_estate['Age at time of purchase']=real_estate['Age at time of purchase'].astype('float64')
2