从多索引数据帧中删除重复索引

2024-09-29 23:22:49 发布

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

使用pivot_table后,我收到一个DataFrame,它有一些重复的索引,如下所示:

enter image description here

如果从底部看第二个条目,它只有1memberid,对应2testscoreid。在DataFrame中有一个对应的列,名为ScoreRatio,我没有在这里显示。我只想用更高的testscoreid值保留{}。在

数据可以在here中找到。在

我尝试使用以下代码,但似乎没有任何影响:

selectedTestsPivotCorrect.reset_index(level=['memberid'])
selectedTestsPivotCorrect.groupby(selectedTestsPivotCorrect.index).last()

如何对我的DataFrame中出现的所有重复(或可能的三元组、四元组等)memberid执行此操作?在

任何建议都将不胜感激。在


Tags: 数据代码dataframeindexheretable条目level

热门问题