Changing an int datatype column to a float

To do this, we first check the datatypes of columns from our real dataset:

data.dtypes 

The following is the output:

We then use the astype method to change the datatype. We pass float to the astype method and call this method on the column, the datatype of which we want to change.

We assign the change back to the original column as follows:

data['Zhvi'] = data.Zhvi.astype(float) 
data.dtypes 

In the following screenshot, we can see that the change has been made—the datatype of our column has been changed from int64 to float64:

Get Mastering Exploratory Analysis with pandas now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.