Pandas:如果NaN

时间:2015-10-06 18:30:28

标签: python pandas dataframe rename multi-index

如何替换下面df的内部索引标签?

Question                                 profile_gender. Gender           
Values                                    Male     Female
Question                    Values                                  
XCS_3. Think of a problem?  NaN        25.192318  25.900784

为:

Question                                 profile_gender. Gender           
Values                                    Male     Female
Question                    Values                                  
XCS_3. Think of a problem?  Okay Done   25.192318  25.900784

我失败的尝试:

df.index = df.index.set_levels(['Okay Done'], 1)

什么都不做,甚至不会抛出错误代码

1 个答案:

答案 0 :(得分:0)

看起来我必须替换非常烦人的整个索引。

df.index = pd.MultiIndex.from_tuples([('XCS_3. Think of a problem?', ' Okay Done')],
                                     names=['Question', 'Values'])