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

The syntax for converting a column to integer in Pandas:

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

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 integer in pandas

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

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

df.info()
 how to convert a column to integer in pandas - the click reader

Here, int32 denotes that the elements of the column are integers of 32 bit.

In Conclusion

This is how you convert a column to integer 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