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

The syntax for converting a column to string in Pandas:

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

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

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

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

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

Note: An object is equivalent to a string in Pandas.

In Conclusion

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

LEAVE A REPLY

Please enter your comment!
Please enter your name here