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()
🌐
GeeksforGeeks
geeksforgeeks.org › pandas › how-to-convert-pandas-columns-to-string
How to Convert Pandas Columns to String - GeeksforGeeks
July 23, 2025 - This method explicitly casts a column to the desired type. ... import pandas as pd import numpy as np # Create a DataFrame with random numerical and string columns np.random.seed(42) data = { 'Numeric_Column': np.random.randint(1, 100, 4), 'String_Column': np.random.choice(['A', 'B', 'C', 'D'], 4) } df = pd.DataFrame(data) # Convert 'Numeric_Column' to string using astype() df['Numeric_Column'] = df['Numeric_Column'].astype(str) # Display the result print("Pandas DataFrame:") display(df)
Discussions

python - Pandas: change data type of Series to String - Stack Overflow
Original DataFrame: Name Age City ... data types: Name string[python] Age int64 City string[python] Salary int64 Category string[python] dtype: object Categorical columns (cat_cols_): ['Name', 'City', 'Category'] ... Sign up to request clarification or add additional context in comments. ... First solution works technically, but replaces content. Copies the strings of one row into all ... More on stackoverflow.com
🌐 stackoverflow.com
Pandas: converting entire dataframe to string type, except for NaN entries
Can't u delete every NaN with regex from your text ? Excuse me if i'm suggesting something irrelevant kinda new to programming More on reddit.com
🌐 r/learnpython
7
1
January 29, 2021
python - Convert columns to string in Pandas - Stack Overflow
I would prefer your answer - because the OP asked for 'all' columns, not individual columns. 2021-11-18T16:40:14.807Z+00:00 ... Save this answer. ... Show activity on this post. Prior to pandas 1.0 (well, 0.25 actually) this was the defacto way of declaring a Series/column as as string: # pandas <= 0.25 # Note to pedants: specifying the type ... More on stackoverflow.com
🌐 stackoverflow.com
Unable to convert a pandas object to a string in my DataFrame
object is just the dtype pandas uses for columns that contain values of type str (and many other Python types). The actual values themselves are still strings: import pandas as pd df = pd.DataFrame([["hello"], ["world"]], columns=["words"]) df.dtypes >>> words object dtype: object type(df.loc[0, "words"]) >>> Using .astype(str) does convert all values to string if they aren't already, but it doesn't change the column dtype by design. The only way around this is to use pandas's own string type via .astype("string"), but that's different from the str type, obviously. What exactly are the issues you are facing with the API? More on reddit.com
🌐 r/learnpython
6
3
December 10, 2021
🌐
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
🌐
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 - First, we discuss why data consistency is important and how it’s achieved by converting all columns to a uniform string data type in a Pandas dataframe. Next, we explore the technique of changing data types to strings using the .astype() function ...
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
🌐
Delft Stack
delftstack.com › home › howto › python pandas › pandas convert column values to string
How to Convert Column Values to String in Pandas | Delft Stack
February 2, 2024 - If we want to change the data type of all column values in the DataFrame to the string type, we can use the applymap() method. import pandas as pd employees_df = pd.DataFrame( { "Name": ["Ayush", "Bikram", "Ceela", "Kusal", "Shanty"], "Score": ...
🌐
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
Find elsewhere
🌐
Saturn Cloud
saturncloud.io › blog › how-to-convert-columns-to-string-in-pandas
How to Convert Columns to String in Pandas | Saturn Cloud Blog
December 2, 2023 - To convert columns to string in Pandas, we can use the astype() method. This method allows us to convert a column to a specified data type.
🌐
Reddit
reddit.com › r/learnpython › pandas: converting entire dataframe to string type, except for nan entries
r/learnpython on Reddit: Pandas: converting entire dataframe to string type, except for NaN entries
January 29, 2021 -

Basically, I know I can use

df = df.astype(str)

to convert every entry in every column to a string, but the issue is that it also converts NaN type entries into a string. Is there a way to replicate the above code without touching NaN entries?

Edit: found one potential solution, though might be a bit on the slower side.

df = df.where(df.isna(), df.astype(str))
🌐
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 ...
🌐
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.
🌐
Appdividend
appdividend.com › converting-columns-to-string-in-pandas-dataframe
Converting Columns to String in Pandas DataFrame
January 7, 2025 - import pandas as pd # Data to be ... conversion: ") print(df.dtypes) # Convert the datatype of the column 'col1' # Using .astype() method df['col1'] = df['col1'].astype(str) print("After conversion: ") print(df.dtypes) You can ...
🌐
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.
🌐
datagy
datagy.io › home › pandas tutorials › pandas dataframes › pandas: convert column values to strings
Pandas: Convert Column Values to Strings • datagy
December 15, 2022 - In the next section, you’ll learn how to use .applymap() to convert all columns in a Pandas dataframe to strings.
🌐
Pandas
pandas.pydata.org › docs › reference › api › pandas.DataFrame.to_string.html
pandas.DataFrame.to_string — pandas 3.0.3 documentation
Buffer to write to. If None, the output is returned as a string. ... The subset of columns to write. Writes all columns by default.
🌐
GeeksforGeeks
geeksforgeeks.org › change-data-type-for-one-or-more-columns-in-pandas-dataframe
Change Data Type for one or more columns in Pandas Dataframe - GeeksforGeeks
May 1, 2025 - Example # Convert the whole dataframe as a string and displaydisplay(df.to_s ... In Pandas, missing data occurs when some values are missing or not collected properly and these missing values are represented as:None: A Python object used to represent missing values in object-type arrays.NaN: A special floating-point value from NumPy which is recognized by all systems that use IE
🌐
W3docs
w3docs.com › python
Convert columns to string in Pandas
import pandas as pd # Create a sample dataframe df = pd.DataFrame({'A': [1, 2, 3], 'B': [4, 5, 6], 'C': [7, 8, 9]}) # Convert all columns to strings df = df.astype(str)
🌐
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 - In this post, we will walk you through the process of converting object data types to string data types in Pandas DataFrames. Before we dive into the how, let’s discuss the why. Why would you want to convert an object data type to a string data type? ... Data Consistency: Ensuring that all data in a specific column is of the same type is crucial for data consistency.