pandas: convert index type in multiindex dataframe

后端 未结 3 2025
别跟我提以往
别跟我提以往 2020-12-30 00:40

Hi have a multiindex dataframe:

tuples = [(\'YTA_Q3\', 1), (\'YTA_Q3\', 2), (\'YTA_Q3\', 3), (\'YTA_Q3\', 4), (\'YTA_Q3\', 99), (\'YTA_Q3\', 96)]
# Index
ind         


        
3条回答
  •  有刺的猬
    2020-12-30 01:19

    I find the current pandas implementation a bit cumbersome, so I use this:

    df1.index = pd.MultiIndex.from_tuples([(ix[0], str(ix[1])) for ix in df1.index.tolist()])

提交回复
热议问题