Pandas:重命名multiindex dataframe中的索引标签

2024-05-19 01:50:44 发布

您现在位置:Python中文网/ 问答频道 /正文

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

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

收件人:

^{pr2}$

我失败的尝试:

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

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


Tags: ofdfindex标签nanprofilegendermale
1条回答
网友
1楼 · 发布于 2024-05-19 01:50:44

看来我必须替换整个索引,这很烦人。在

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

相关问题 更多 >

    热门问题