Pandas 删除多重索引中的重复索引,而不考虑顺序

Pandas 删除多重索引中的重复索引,而不考虑顺序,pandas,indexing,duplicates,series,multi-index,Pandas,Indexing,Duplicates,Series,Multi Index,以一个带有多索引的简单的pd系列为例: #create the multiindex and data mult = pd.MultiIndex.from_product([[1,2,3],[1,2,3]],names=['factor1','factor2']) data = np.arange(1,4)*np.arange(1,4)[:,np.newaxis] #create the series ser = (pd.Series(data.ravel(),

以一个带有多索引的简单的pd系列为例:

#create the multiindex and data
mult = pd.MultiIndex.from_product([[1,2,3],[1,2,3]],names=['factor1','factor2'])
data = np.arange(1,4)*np.arange(1,4)[:,np.newaxis]

#create the series
ser = (pd.Series(data.ravel(),
                index=mult,
                name='product')
       .sort_values(ascending=False))

print(ser)
factor1  factor2
3        3          9
         2          6
2        3          6
         2          4
3        1          3
1        3          3
2        1          2
1        2          2
         1          1
Name: product, dtype: int64
如何删除重复索引,而不考虑顺序,以便最终系列

factor1  factor2
3        3          9
         2          6
2        2          4
3        1          3
2        1          2
1        1          1
Name: product, dtype: int64

我们的想法是,
2*3
3*2
是相同的因素,因此我们想去掉其中一个。我已经尝试过删除重复项,但这会消除任何重复的产品,而不管它们的索引如何(因此
1*0
2*0
都会被视为重复项)。

Hacky

ser[~pd.DataFrame(np.sort(np.array(ser.index.tolist()), 1)).duplicated().values]

factor1  factor2
3        3          9
         2          6
2        2          4
3        1          3
2        1          2
1        1          1
Name: product, dtype: int64