One way to convert to string is to use astype:

total_rows['ColumnID'] = total_rows['ColumnID'].astype(str)

However, perhaps you are looking for the to_json function, which will convert keys to valid json (and therefore your keys to strings):

In [11]: df = pd.DataFrame([['A', 2], ['A', 4], ['B', 6]])

In [12]: df.to_json()
Out[12]: '{"0":{"0":"A","1":"A","2":"B"},"1":{"0":2,"1":4,"2":6}}'

In [13]: df[0].to_json()
Out[13]: '{"0":"A","1":"A","2":"B"}'

Note: you can pass in a buffer/file to save this to, along with some other options...

Answer from Andy Hayden on Stack Overflow
🌐
GeeksforGeeks
geeksforgeeks.org › pandas › how-to-convert-pandas-columns-to-string
How to Convert Pandas Columns to String - GeeksforGeeks
July 23, 2025 - Converting columns to strings allows easier manipulation when performing string operations such as pattern matching, formatting or concatenation. Pandas provides multiple ways to achieve this conversion and choosing the best method can depend on factors like the size of your dataset and the ...
Discussions

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 multiple columns to string in pandas dataframe - Stack Overflow
I have a pandas data frame with different data types. I want to convert more than one column in the data frame to string type. I have individually done for each column but want to know if there is an More on stackoverflow.com
🌐 stackoverflow.com
How I convert float to string in this case?
You shouldn't call your variable sum, as that's a name of a built in function: https://docs.python.org/3/library/functions.html#sum Your problem however, stems from trying to add a string to a float. Could you please tell me, what is Adam + 5? Well, you can't, because it makes no mathematical sense. You didn't save the string representation str(sum), so sum never changed to a string What your research found is f-strings and they are very easy to use. Try: print(f"the sum of the values is {sum}") Simply, put an f before a string starts, then any string that you want goes between " and ", while any variables or other values go between { and } More on reddit.com
🌐 r/learnpython
4
2
August 22, 2022
Pandas DataFrame tries to convert a string into a float, while adding it to a column
Well you're using np.nan which is a float. Interestingly though, it only raises the error after the first item has been added. >>> df = pd.DataFrame() >>> df['foo'] = [np.nan] * len(df) >>> df Empty DataFrame Columns: [foo] Index: [] Note the type is float64 >>> df.dtypes foo float64 dtype: object However, pandas converts it. >>> df.at['file_path', 'foo'] = 'file1' >>> df.dtypes foo object dtype: object Second time round, it raises the error - not sure why that is exactly. >>> df['bar'] = [np.nan] * len(df) >>> df.dtypes foo object bar float64 dtype: object >>> df.at['file_path', 'bar'] = 'file1' Traceback (most recent call last): You can use an empty string '' instead of np.nan - or you could initialize your dataframe with values. You may also want to check out pathlib from pathlib import Path file_paths = ... df = pd.DataFrame({ Path(p).stem: [p] for p in file_paths }) .stem from pathlib is the filename without the extension. More on reddit.com
🌐 r/learnpython
4
2
December 13, 2021
🌐
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.
🌐
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 - Pandas Convert Column to datetime – object/string, integer, CSV & Excel · How to Convert a Float Array to an Integer Array in Python with NumPy · In Pandas programming, the .to_string() function emerges as a concise yet potent tool for ...
🌐
Spark By {Examples}
sparkbyexamples.com › home › pandas › convert multiple columns to string in pandas dataframe
Convert Multiple Columns to String in Pandas DataFrame - Spark By {Examples}
December 5, 2024 - To convert multiple columns to strings in a Pandas DataFrame, you can use the astype() method and specify the columns you want to convert. In this
🌐
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 - 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)
🌐
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.
Find elsewhere
🌐
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)
🌐
Statology
statology.org › home › how to convert pandas dataframe columns to strings
How to Convert Pandas DataFrame Columns to Strings
July 29, 2020 - And once again we can verify that they’re strings by using dtypes: df.dtypes player object points object assists object dtype: object · Lastly, we can convert every column in a DataFrame to strings by using the following syntax:
🌐
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 ...
🌐
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": ...
🌐
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))
🌐
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 - A clear, step-by-step roadmap to ... it all out. ... When working with data in Python, you’ve probably encountered Pandas. It’s a powerful tool that simplifies data manipulation and analysis. An essential operation you might need to perform is converting a column in your DataFrame to a string ...
🌐
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
🌐
GeeksforGeeks
geeksforgeeks.org › pandas › pandas-convert-column-to-string-type
Pandas Convert Column To String Type - GeeksforGeeks
July 23, 2025 - The astype() method in Pandas is a straightforward way to change the data type of a column to any desired type. The astype method has the following syntax: ... Here we define that the numeric type for the dataset should be converted to a string ...
🌐
Iditect
iditect.com › faq › python › convert-columns-to-string-in-pandas.html
Convert columns to string in Pandas
In this example, the .astype(str) method is applied to the specified columns, converting their data types to strings (object in pandas). As a result, the dtypes of the columns change from int64 to object. If you want to convert all columns in the DataFrame to strings, you can apply .astype(str) ...
🌐
Edureka Community
edureka.co › home › community › categories › python › how to convert multiple columns to string in...
How to convert multiple columns to string in pandas dataframe | Edureka Community
July 19, 2019 - I have dataframes with different datatypes(code is given below). repair['SCENARIO']=repair[ ... pass multiple columns and convert them into strings.
🌐
Scaler
scaler.com › home › topics › pandas › convert column to string in pandas
Convert Column to String in Pandas - Scaler Topics
December 19, 2022 - The Pandas str.split() method may be used to split an entire series. The string is split into a list The Gender column in this data is divided using the split function every "e." Because the option is set to 1, the maximum number of separations ...
🌐
Educative
educative.io › answers › how-to-convert-a-column-in-text-string-output-in-python
How to convert a column in text/string output in Python
In this Answer, we explored two methods to convert a column in the pandas DataFrame to a text or string output and print it to the console using the .to_string() method and the .to_csv() method.