>>> df = pd.DataFrame({'col':['a',0]}) >>> df col 0 a 1 0 >>> df['col'] = 'str' + df['col'].astype(str) >>> df col 0 stra 1 str0
Here is what the above code is Doing:
1. Creating a DataFrame with a column of type object and a column of type int
2. Changing the type of the object column to string
3. Adding the string ‘str’ to the beginning of each value in the object column
4. Changing the type of the int column to string
5. Adding the string ‘str’ to the beginning of each value in the int column
The result is a DataFrame with two columns of type string.