Dataframe Slice does not remove Index Values

后端 未结 3 433
悲哀的现实
悲哀的现实 2020-12-03 23:59

I recently had this issue with a large dataframe and its associated multi index. This simplified example will demonstrate the issue.

import pandas as pd
imp         


        
3条回答
  •  旧巷少年郎
    2020-12-04 00:08

    You can make the MultiIndex unique by

    df_slice.index = pd.MultiIndex.from_tuples(df_slice.index.unique(), names=idx.names)
    

    which yields the index

    MultiIndex(levels=[[u'A', u'B'], [5]],
               labels=[[0, 1], [0, 0]])
    

提交回复
热议问题