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…
Related Posts:
- Pandas error “Can only use .str accessor with string values”
- Convert a Unicode string to a string in Python (containing extra symbols)python string unicode type-conversion
- Checking if a string can be converted to float in Python
- How do I lowercase a string in Python?
- how to sort pandas dataframe from one column
- How do I get a substring of a string in Python?
- Renaming column names in Pandas
- How to reset index in a pandas dataframe? [duplicate]
- Does Python have a string ‘contains’ substring method?
- How to read a file line-by-line into a list?
- Delete a column from a Pandas DataFrame
- strip(char) on a string
- How to deal with SettingWithCopyWarning in Pandas
- How to deal with SettingWithCopyWarning in Pandas
- Constructing pandas DataFrame from values in variables gives “ValueError: If using all scalar values, you must pass an index”
- How to iterate over rows in a DataFrame in Pandas
- pandas read_json: “If using all scalar values, you must pass an index”
- How to iterate over rows in a DataFrame in Pandas
- How to convert list to string [duplicate]
- TypeError: a bytes-like object is required, not ‘str’ when writing to a file in Python3
- Writing a pandas DataFrame to CSV file
- Truth value of a Series is ambiguous. Use a.empty, a.bool(), a.item(), a.any() or a.all()
- Truth value of a Series is ambiguous. Use a.empty, a.bool(), a.item(), a.any() or a.all()
- Writing a pandas DataFrame to CSV file
- Print string to text file
- Best way to convert string to bytes in Python 3?
- Pythonic way to create a long multi-line string
- Best way to convert string to bytes in Python 3?
- Does Python have a string ‘contains’ substring method?
- TypeError: not all arguments converted during string formatting python
- Adding new column to existing DataFrame in Python pandas
- Modifing data while using iterrows() does not work
- ImportError: No module named pandas
- How to change the order of DataFrame columns?
- How to change the order of DataFrame columns?
- ImportError: No module named pandas. Pandas installed pip
- ‘str’ object does not support item assignment
- What does `ValueError: cannot reindex from a duplicate axis` mean?
- Pandas DataFrame Groupby two columns and get counts
- How do I append one string to another in Python?
- How can I use the apply() function for a single column?
- How to show all columns’ names on a large pandas dataframe?
- Convenient way to deal with ValueError: cannot reindex from a duplicate axis
- ValueError: Unknown label type: ‘continuous’
- How to groupby based on two columns in pandas?
- How do I append one string to another in Python?
- How to fix IndexError: invalid index to scalar variable
- “Series objects are mutable and cannot be hashed” error
- Random string generation with upper case letters and digits
- How can I split and parse a string in Python?
- How to deal with SettingWithCopyWarning in Pandas
- How do I parse a string to a float or int?
- Merging dataframes on index with pandas
- ImportError: No module named pandas
- TypeError: ‘Series’ objects are mutable, thus they cannot be hashed problemwith column
- Create a Pandas Dataframe by appending one row at a time
- How to replace NaN values by Zeroes in a column of a Pandas Dataframe?
- ValueError: Length of values does not match length of index | Pandas DataFrame.unique()
- How to read a text file into a string variable and strip newlines?
- Convert bytes to a string
- Convert Python dict into a dataframe
- How to print like printf in Python3?
- re.sub erroring with “Expected string or bytes-like object”
- Creating an empty Pandas DataFrame, then filling it?
- How to read a text file into a string variable and strip newlines?
- How do I select rows from a DataFrame based on column values?
- How do I select rows from a DataFrame based on column values?
- DataFrame constructor not properly called! error
- Pandas group-by and sum
- How do I get the row count of a Pandas DataFrame?
- Python pandas groupby aggregate on multiple columns, then pivot
- Python Pandas Counting the Occurrences of a Specific value
- Convert pandas dataframe to NumPy array
- Count unique values per groups with Pandas
- DataFrame constructor not properly called
- Convert pandas Series to DataFrame
- Python convert tuple to string
- Error:cannot convert float NaN to integer in pandas
- ImportError: Missing required dependencies [‘numpy’]
- write() versus writelines() and concatenated strings
- Replacing column values in a pandas DataFrame
- Error”Can only compare identically-labeled Series objects” and sort_index
- Why is it string.join(list) instead of list.join(string)?
- Why is it string.join(list) instead of list.join(string)?
- Split a string into 2 in Python
- How to iterate over rows in a DataFrame in Pandas
- Pandas group-by and sum
- How do I get the row count of a Pandas DataFrame?
- Python Pandas – Missing required dependencies [‘numpy’] 1
- Pandas “Can only compare identically-labeled DataFrame objects” error
- Pandas: ValueError: cannot convert float NaN to integer
- Best way to strip punctuation from a string
- Split string with multiple delimiters in Python [duplicate]
- Get list from pandas dataframe column or row?
- pandas DataFrame “no numeric data to plot” error
- ValueError: Length of values does not match length of index | Pandas DataFrame.unique()
- ‘DataFrame’ object has no attribute ‘sort’
- ‘DataFrame’ object has no attribute ‘sort’
- How to check if the string is empty?
- pandas: merge (join) two data frames on multiple columns