大熊猫保持重复的最高价值

As3*_*tin 5 python duplicates python-2.7 pandas

我有类似的数据:

id value duplicate
a   200  yes
a   12   yes
b   42   yes
c   12   no
b   532  yes
b   21   yes
...
Run Code Online (Sandbox Code Playgroud)

跟踪我使用的重复项df['duplicate'] = df.duplicated('id', keep=False)但是,我想保留最高的那些value并且标记或删除其他重复项.有什么建议?

As3*_*tin 9

啊,我不知道为什么我没想到这个. df.sort(['id', 'value']) df['is_duplicated'] = df.duplicated('id', keep='first')

抱歉!