Back
I want to change a dataframes' index (rows) from float64 to string or Unicode.
I thought this would work but not:
#check typetype(df.index)'pandas.core.index.Float64Index'#change type to unicodeif not isinstance(df.index, unicode): df.index = df.index.astype(unicode)
#check type
type(df.index)
'pandas.core.index.Float64Index'
#change type to unicode
if not isinstance(df.index, unicode):
df.index = df.index.astype(unicode)
error message:
TypeError: Setting <class 'pandas.core.index.Float64Index'> dtype to anything other than float64 or object is not supported
For Python 2, you can refer the following code as this works for me:
df.index = df.index.map(unicode)
And for Python 3, the unicode type does not exist and is replaced by str. Refer the following code:
df.index = df.index.map(str)
31k questions
32.8k answers
501 comments
693 users