23
我想将float64的数据框索引(行)从字符串或unicode更改为字符串。pandas - 将df.index从float64更改为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)
错误消息:
TypeError: Setting <class 'pandas.core.index.Float64Index'> dtype to anything other than float64 or object is not supported
这对Python 3.5无效。你有什么想法,为什么? –
原来的海报使用的是Python 2.在Python 3中'unicode'类型不再存在,而必须使用'str'类型(基本上,Python 2中称为“str”的字段在Python 3和'unicode'同样变成了'str')。 请参阅[此问题](http://stackoverflow.com/questions/19877306/nameerror-global-name-unicode-is-not-defined-in-python-3)以获取更多信息。 – Arthur