You can use pandas .astype(float) function to convert a column to float in Pandas.

The syntax for converting a column to float in Pandas:

df['column_name'] = df['column_name'].astype(float)

The following syntax can be demonstrated using an example in Python:

import pandas as pd

df = pd.DataFrame({'Name': ['Steve Smith', 'Joe Nadal', 'Roger Federer'], 'Age':['32', '34', '36']})

df.info()
how to convert a column to float in pandas

As we can see the Age column is an object column. Now, converting it into a float.

df['Age'] = df['Age'].astype(float)

df.info()
how to convert a column to float in pandas - The Click Reader

Here, float64 denotes that the elements of the column are float of 64 bit.

In Conclusion

This is how you convert a column to float in Pandas. Also, learn how to convert a column to string in pandas.

LEAVE A REPLY

Please enter your comment!
Please enter your name here