To convert all values in a Pandas dataframe from integer to string datatype in Python, you can use the astype()
method with 'str'
as the argument. Here's an example:
main.py255 chars12 lines
Output:
main.py59 chars5 lines
In the above code, first we import the Pandas library. Then we define a sample dataframe df
with integer values in each column. Finally, we use the astype()
method to convert all the columns to the string datatype, and then print the datatype of all columns in the dataframe.
gistlibby LogSnag