我有一个Multiindex(2级)数据框,如下所示:
coords wref
-----------------
0 0 18917 0*
1 23013 0*
1 0 23013 0
1 27109 1
2 0 23013 2
1 27108 5
3 0 27109 0*
1 27109 0*
位于索引0和3的Level-0具有非唯一的wref
系列(它们每个都是[0,0](请参见星号*))。
wref
系列将至少包含2个元素,但是最多可以变化为8个。
是否有比以下更有效的方法来获取关联记录的0级索引?
non_unique_idx = [i for i in records.index.unique(level=0) if not records.wref.loc[i].is_unique]
这将用于例如删除元素以仅获取具有唯一wref系列的记录。