pandas - change df.index from float64 to unicode or string

后端 未结 2 1629
终归单人心
终归单人心 2020-12-23 11:06

I want to change a dataframes\' index (rows) from float64 to string or unicode.

I thought this would work but apparently not:

#check type
type(df.in         


        
2条回答
  •  刺人心
    刺人心 (楼主)
    2020-12-23 11:42

    For python 3 and pandas 0.19 or latter versions, I found the following works fine for me

        # Python 3 (pandas 0.19 or latter versions)
        df.index.astype(str, copy = False)
    

提交回复
热议问题