A new answer to reflect the most current practices: as of now (v1.2.4), neither astype('str') nor astype(str) work.

As per the documentation, a Series can be converted to the string datatype in the following ways:

df['id'] = df['id'].astype("string")

df['id'] = pandas.Series(df['id'], dtype="string")

df['id'] = pandas.Series(df['id'], dtype=pandas.StringDtype)

End to end example:

import pandas as pd

# Create a sample DataFrame
data = {
    'Name': ['John', 'Alice', 'Bob', 'John', 'Alice'],
    'Age': [25, 30, 35, 25, 30],
    'City': ['New York', 'London', 'Paris', 'New York', 'London'],
    'Salary': [50000, 60000, 70000, 50000, 60000],
    'Category': ['A', 'B', 'C', 'A', 'B']
}

df = pd.DataFrame(data)

# Print the DataFrame
print("Original DataFrame:")
print(df)
print("\nData types:")
print(df.dtypes)
cat_cols_ = None
# Apply the code to change data types
if not cat_cols_:
    # Get the columns with object data type
    object_columns = df.select_dtypes(include=['object']).columns.tolist()
    
    if len(object_columns) > 0:
        print(f"\nObject columns found, converting to string: {object_columns}")
        
        # Convert object columns to string type
        df[object_columns] = df[object_columns].astype('string')
    
    # Get the categorical columns (including string and category data types)
    cat_cols_ = df.select_dtypes(include=['category', 'string']).columns.tolist()

# Print the updated DataFrame and data types
print("\nUpdated DataFrame:")
print(df)
print("\nUpdated data types:")
print(df.dtypes)
print(f"\nCategorical columns (cat_cols_): {cat_cols_}")
Original DataFrame:
    Name  Age      City  Salary Category
0   John   25  New York   50000        A
1  Alice   30    London   60000        B
2    Bob   35     Paris   70000        C
3   John   25  New York   50000        A
4  Alice   30    London   60000        B

Data types:
Name        object
Age          int64
City        object
Salary       int64
Category    object
dtype: object

Object columns found, converting to string: ['Name', 'City', 'Category']

Updated DataFrame:
    Name  Age      City  Salary Category
0   John   25  New York   50000        A
1  Alice   30    London   60000        B
2    Bob   35     Paris   70000        C
3   John   25  New York   50000        A
4  Alice   30    London   60000        B

Updated data types:
Name        string[python]
Age                  int64
City        string[python]
Salary               int64
Category    string[python]
dtype: object

Categorical columns (cat_cols_): ['Name', 'City', 'Category']
Answer from rocksNwaves on Stack Overflow
🌐
GeeksforGeeks
geeksforgeeks.org › pandas › pandas-convert-column-to-string-type
Pandas Convert Column To String Type - GeeksforGeeks
July 23, 2025 - Now, lets see how lambda can help us along with apply function to convert column to string type. Lambda function will be a quick way of telling the computer to apply the changes for each value ... import pandas as pd # sample data data = {'NumericColumn': [1, 2, 3, 4]} df = pd.DataFrame(data) df['NumericColumn'] = df['NumericColumn'].apply(lambda x: str(x)) df.info()
🌐
Spark By {Examples}
sparkbyexamples.com › home › pandas › pandas convert column to string type
Pandas Convert Column to String Type - Spark By {Examples}
July 3, 2025 - In this article, I will explain how to convert single column or multiple columns to string type in pandas DataFrame, here, I will demonstrate using
Top answer
1 of 11
251

A new answer to reflect the most current practices: as of now (v1.2.4), neither astype('str') nor astype(str) work.

As per the documentation, a Series can be converted to the string datatype in the following ways:

df['id'] = df['id'].astype("string")

df['id'] = pandas.Series(df['id'], dtype="string")

df['id'] = pandas.Series(df['id'], dtype=pandas.StringDtype)

End to end example:

import pandas as pd

# Create a sample DataFrame
data = {
    'Name': ['John', 'Alice', 'Bob', 'John', 'Alice'],
    'Age': [25, 30, 35, 25, 30],
    'City': ['New York', 'London', 'Paris', 'New York', 'London'],
    'Salary': [50000, 60000, 70000, 50000, 60000],
    'Category': ['A', 'B', 'C', 'A', 'B']
}

df = pd.DataFrame(data)

# Print the DataFrame
print("Original DataFrame:")
print(df)
print("\nData types:")
print(df.dtypes)
cat_cols_ = None
# Apply the code to change data types
if not cat_cols_:
    # Get the columns with object data type
    object_columns = df.select_dtypes(include=['object']).columns.tolist()
    
    if len(object_columns) > 0:
        print(f"\nObject columns found, converting to string: {object_columns}")
        
        # Convert object columns to string type
        df[object_columns] = df[object_columns].astype('string')
    
    # Get the categorical columns (including string and category data types)
    cat_cols_ = df.select_dtypes(include=['category', 'string']).columns.tolist()

# Print the updated DataFrame and data types
print("\nUpdated DataFrame:")
print(df)
print("\nUpdated data types:")
print(df.dtypes)
print(f"\nCategorical columns (cat_cols_): {cat_cols_}")
Original DataFrame:
    Name  Age      City  Salary Category
0   John   25  New York   50000        A
1  Alice   30    London   60000        B
2    Bob   35     Paris   70000        C
3   John   25  New York   50000        A
4  Alice   30    London   60000        B

Data types:
Name        object
Age          int64
City        object
Salary       int64
Category    object
dtype: object

Object columns found, converting to string: ['Name', 'City', 'Category']

Updated DataFrame:
    Name  Age      City  Salary Category
0   John   25  New York   50000        A
1  Alice   30    London   60000        B
2    Bob   35     Paris   70000        C
3   John   25  New York   50000        A
4  Alice   30    London   60000        B

Updated data types:
Name        string[python]
Age                  int64
City        string[python]
Salary               int64
Category    string[python]
dtype: object

Categorical columns (cat_cols_): ['Name', 'City', 'Category']
2 of 11
127

You can convert all elements of id to str using apply

df.id.apply(str)

0        123
1        512
2      zhub1
3    12354.3
4        129
5        753
6        295
7        610

Edit by OP:

I think the issue was related to the Python version (2.7.), this worked:

df['id'].astype(basestring)
0        123
1        512
2      zhub1
3    12354.3
4        129
5        753
6        295
7        610
Name: id, dtype: object
🌐
GeeksforGeeks
geeksforgeeks.org › pandas › how-to-convert-pandas-columns-to-string
How to Convert Pandas Columns to String - GeeksforGeeks
July 23, 2025 - Pandas provides multiple ways to ... In this article, we’ll explore several ways to convert Pandas columns to strings · astype() method is one of the most straightforward ways to convert a column’s data type....
🌐
Pandas
pandas.pydata.org › docs › reference › api › pandas.DataFrame.astype.html
pandas.DataFrame.astype — pandas 3.0.3 documentation
Use a str, numpy.dtype, pandas.ExtensionDtype or Python type to cast entire pandas object to the same type. Alternatively, use a mapping, e.g. {col: dtype, …}, where col is a column label and dtype is a numpy.dtype or Python type to cast one or more of the DataFrame’s columns to column-specific types. ... This keyword is now ignored; changing its value will have no impact on the method.
🌐
Saturn Cloud
saturncloud.io › blog › how-to-convert-columns-to-string-in-pandas
How to Convert Columns to String in Pandas | Saturn Cloud Blog
June 19, 2023 - Let’s say we have a Pandas DataFrame df that contains a column named employee_id that we want to convert to a string. We can use the following code to do this: # Converting 'employee_id' to string df['employee_id'] = df['employee_id'].astype(str) # Displaying the types of data after conversion print("\nTypes of data after conversion:\n", df.dtypes)
🌐
Saturn Cloud
saturncloud.io › blog › python-pandas-converting-object-to-string-type-in-dataframes
Python Pandas: Converting Object to String Type in DataFrames | Saturn Cloud Blog
July 10, 2023 - Type of column B before converting: object Type of column B after converting: string · In the code above, we first import the Pandas library. We then create a DataFrame with two columns: A and B.
Find elsewhere
🌐
Medium
medium.com › @whyamit404 › steps-to-pandas-convert-column-to-string-6154c98e3ae5
Steps to Pandas Convert Column to String | by whyamit404 | Medium
April 12, 2025 - How do I check the column’s data type after conversion? Use the dtypes attribute to check the datatype of each column in your DataFrame. It’s a straightforward way to confirm that your conversion was successful. Is there a way to convert without changing the original DataFrame? Absolutely! You can create a copy of the column first before converting: ... To wrap it up, converting a column to a string in Pandas is a straightforward process that can significantly enhance your data analysis.
🌐
Sentry
sentry.io › sentry answers › python › change a column type in a dataframe in python pandas
Change a column type in a DataFrame in Python Pandas | Sentry
Which one to use will depend on the data types we’re converting from and to. If we want to convert a column from any data type to one specific data type (e.g. integer, float, string), we should use the astype method.
🌐
Statology
statology.org › home › how to convert pandas dataframe columns to strings
How to Convert Pandas DataFrame Columns to Strings
July 29, 2020 - #convert every column to strings df = df.astype(str) #check data type of each column df.dtypes player object points object assists object dtype: object
Top answer
1 of 5
150

You need astype:

df['zipcode'] = df.zipcode.astype(str)
#df.zipcode = df.zipcode.astype(str)

For converting to categorical:

df['zipcode'] = df.zipcode.astype('category')
#df.zipcode = df.zipcode.astype('category')

Another solution is Categorical:

df['zipcode'] = pd.Categorical(df.zipcode)

Sample with data:

import pandas as pd

df = pd.DataFrame({'zipcode': {17384: 98125, 2680: 98107, 722: 98005, 18754: 98109, 14554: 98155}, 'bathrooms': {17384: 1.5, 2680: 0.75, 722: 3.25, 18754: 1.0, 14554: 2.5}, 'sqft_lot': {17384: 1650, 2680: 3700, 722: 51836, 18754: 2640, 14554: 9603}, 'bedrooms': {17384: 2, 2680: 2, 722: 4, 18754: 2, 14554: 4}, 'sqft_living': {17384: 1430, 2680: 1440, 722: 4670, 18754: 1130, 14554: 3180}, 'floors': {17384: 3.0, 2680: 1.0, 722: 2.0, 18754: 1.0, 14554: 2.0}})
print (df)
       bathrooms  bedrooms  floors  sqft_living  sqft_lot  zipcode
722         3.25         4     2.0         4670     51836    98005
2680        0.75         2     1.0         1440      3700    98107
14554       2.50         4     2.0         3180      9603    98155
17384       1.50         2     3.0         1430      1650    98125
18754       1.00         2     1.0         1130      2640    98109

print (df.dtypes)
bathrooms      float64
bedrooms         int64
floors         float64
sqft_living      int64
sqft_lot         int64
zipcode          int64
dtype: object

df['zipcode'] = df.zipcode.astype('category')

print (df)
       bathrooms  bedrooms  floors  sqft_living  sqft_lot zipcode
722         3.25         4     2.0         4670     51836   98005
2680        0.75         2     1.0         1440      3700   98107
14554       2.50         4     2.0         3180      9603   98155
17384       1.50         2     3.0         1430      1650   98125
18754       1.00         2     1.0         1130      2640   98109

print (df.dtypes)
bathrooms       float64
bedrooms          int64
floors          float64
sqft_living       int64
sqft_lot          int64
zipcode        category
dtype: object
2 of 5
35

With pandas >= 1.0 there is now a dedicated string datatype:

1) You can convert your column to this pandas string datatype using .astype('string'):

df['zipcode'] = df['zipcode'].astype('string')

2) This is different from using str which sets the pandas object datatype:

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

3) For changing into categorical datatype use:

df['zipcode'] = df['zipcode'].astype('category')

You can see this difference in datatypes when you look at the info of the dataframe:

df = pd.DataFrame({
    'zipcode_str': [90210, 90211] ,
    'zipcode_string': [90210, 90211],
    'zipcode_category': [90210, 90211],
})

df['zipcode_str'] = df['zipcode_str'].astype(str)
df['zipcode_string'] = df['zipcode_str'].astype('string')
df['zipcode_category'] = df['zipcode_category'].astype('category')

df.info()

# you can see that the first column has dtype object
# while the second column has the new dtype string
# the third column has dtype category
 #   Column            Non-Null Count  Dtype   
---  ------            --------------  -----   
 0   zipcode_str       2 non-null      object  
 1   zipcode_string    2 non-null      string  
 2   zipcode_category  2 non-null      category
dtypes: category(1), object(1), string(1)

From the docs:

The 'string' extension type solves several issues with object-dtype NumPy arrays:

  1. You can accidentally store a mixture of strings and non-strings in an object dtype array. A StringArray can only store strings.

  2. object dtype breaks dtype-specific operations like DataFrame.select_dtypes(). There isn’t a clear way to select just text while excluding non-text, but still object-dtype columns.

  3. When reading code, the contents of an object dtype array is less clear than string.

More info on working with the new string datatype can be found here: https://pandas.pydata.org/pandas-docs/stable/user_guide/text.html

🌐
Seaborn Line Plots
marsja.se › home › programming › pandas convert all columns to string: a comprehensive guide
Pandas Convert All Columns to String: A Comprehensive Guide
September 17, 2025 - In Pandas, the .astype() method can be used for data type manipulation. When applied to a single column, such as df['Column'].astype(str), it transforms the data within that column into strings.
🌐
Statology
statology.org › home › how to change column type in pandas (with examples)
How to Change Column Type in Pandas (With Examples)
November 28, 2022 - Note: You can find the complete documentation for the pandas astype() function here. The following tutorials explain how to perform other common conversions in pandas: How to Convert Pandas DataFrame Columns to Strings How to Convert Timestamp ...
🌐
Scaler
scaler.com › home › topics › pandas › convert column to string in pandas
Convert Column to String in Pandas - Scaler Topics
December 19, 2022 - We will thus learn how Pandas gives us the ability to edit, change, and process string data-frames using certain built-in methods by expanding it here. Some of the built-in functions in the Pandas library are frequently used to manipulate strings in data frames. We will first learn how to use pandas to construct a string data-frame by defining dataframe string create the pandas series, and pandas convert the column to a string:
🌐
datagy
datagy.io › home › pandas tutorials › pandas dataframes › pandas: convert column values to strings
Pandas: Convert Column Values to Strings • datagy
December 15, 2022 - Let’s get started by using the preferred method for using Pandas to convert a column to a string. Pandas comes with a column (series) method, .astype(), which allows us to re-cast a column into a different data type.
🌐
Appdividend
appdividend.com › converting-columns-to-string-in-pandas-dataframe
Converting Columns to String in Pandas DataFrame
January 7, 2025 - You can convert any columns of a DataFrame to string in Pandas using the “astype()” or “apply()” function. In real life, when you are working on a DataFrame, you might have mixed data type columns, and that’s where you need a conversion ...
🌐
Pandas
pandas.pydata.org › docs › reference › api › pandas.DataFrame.to_string.html
pandas.DataFrame.to_string — pandas 3.0.3 documentation
Max width to truncate each column in characters. By default, no limit. ... Set character encoding. ... If buf is None, returns the result as a string.