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
- Renaming column names in Pandas
- Does Python have a string ‘contains’ substring method?
- How to deal with SettingWithCopyWarning in Pandas
- How to deal with SettingWithCopyWarning in Pandas
- How to iterate over rows in a DataFrame in Pandas
- Pythonic way to create a long multi-line string
- TypeError: not all arguments converted during string formatting python
- Adding new column to existing DataFrame in Python pandas
- ImportError: No module named pandas
- How to change the order of DataFrame columns?
- How to change the order of DataFrame columns?
- How do I append one string to another in Python?
- How can I use the apply() function for a single column?
- Convenient way to deal with ValueError: cannot reindex from a duplicate axis
- How to fix IndexError: invalid index to scalar variable
- Random string generation with upper case letters and digits
- Merging dataframes on index with pandas
- Convert Python dict into a dataframe
- re.sub erroring with “Expected string or bytes-like object”
- 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?
- 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
- Convert pandas dataframe to NumPy array
- Error:cannot convert float NaN to integer in pandas
- Replacing column values in a pandas DataFrame
- Split a string into 2 in Python
- How do I get the row count of a Pandas DataFrame?
- Python Pandas – Missing required dependencies [‘numpy’] 1
- Get list from pandas dataframe column or row?
- pandas DataFrame “no numeric data to plot” error
- ‘DataFrame’ object has no attribute ‘sort’
- TypeError: cannot unpack non-iterable int objec
- Pandas DataFrame column to list
- Rename Pandas DataFrame Index
- pandas: filter rows of DataFrame with operator chaining
- How do I convert a list of ascii values to a string in python?
- Convert DataFrame column type from string to datetime, dd/mm/yyyy format
- Pandas how to use pd.cut()
- How to Read .txt in Pandas
- Get a list from Pandas DataFrame column headers
- How can I concatenate str and int objects?
- How can I convert a character to a integer in Python, and viceversa?
- How to check whether a pandas DataFrame is empty?
- Python TypeError: cannot convert the series to
when trying to do math on dataframe - Shuffle DataFrame rows
- Remove the first character of a string
- AttributeError: ‘list’ object has no attribute ‘replace’ when trying to remove character
- How to iterate over columns of pandas dataframe to run regression
- JSON to pandas DataFrame
- Converting between datetime and Pandas Timestamp objects
- Remove all special characters, punctuation and spaces from string
- Creating a Pandas DataFrame from a Numpy array: How do I specify the index column and column headers?
- How can I splice a string?
- Modify the legend of pandas bar plot
- Selecting/excluding sets of columns in pandas
- How to add title to seaborn boxplot
- How to check if type of a variable is string?
- Deleting DataFrame row in Pandas based on column value
- Map to List error: Series object not callable
- Pandas long to wide reshape, by two variables
- Pandas DataFrame: replace all values in a column, based on condition
- How to convert string to datetime format in pandas python?
- Remove quotes from String in Python
- Data type conversion error: ValueError: Cannot convert non-finite values (NA or inf) to integer
- Pandas – How to flatten a hierarchical index in columns
- Find the nth occurrence of substring in a string
- How to convert ‘binary string’ to normal string in Python3?
- Properly formatted multiplication table
- Plot correlation matrix using pandas
- Python: Converting string into decimal number
- How to compare individual characters in two strings in Python 3
- Plotting multiple lines, in different colors, with pandas dataframe
- Groupby value counts on the dataframe pandas
- TypeError: cannot concatenate a non-NDFrame object
- Pandas index column title or name
- ImportError: No module named ‘xlrd’
- How to repeat a string with spaces?
- Building multi-regression model throws error: `Pandas data cast to numpy dtype of object. Check input data with np.asarray(data).`
- Moving Average Pandas
- Importing Pandas gives error AttributeError: module ‘pandas’ has no attribute ‘core’ in iPython Notebook
- matplotlib: plot multiple columns of pandas data frame on the bar chart
- Concat DataFrame Reindexing only valid with uniquely valued Index objects
- Float must be a string or a number?
- How to convert index of a pandas dataframe into a column
- Replacing Pandas or Numpy Nan with a None to use with MysqlDB
- Convert floats to ints in Pandas?
- pandas comparison raises TypeError: cannot compare a dtyped [float64] array with a scalar of type [bool]
- How to get ° character in a string in python?
- Got continuous is not supported error in RandomForestRegressor
- Extract first and last row of a dataframe in pandas
- Mutable strings in Python
- ValueError: Must pass DataFrame with boolean values only
- Extracting specific selected columns to new DataFrame as a copy
- TypeError: coercing to Unicode: need string or buffer