我有一个数据帧df,我需要找出是否有一些player_id在这个季节改变了它的team值:
player_id team
1 Liverpool
2 Manchester
1 Liverpool
2 Manchester
1 Liverpool
2 Tottenham要查找重复的对,我只需:
duplicate = df[df.duplicated(['player_id', 'team'])] 但数据帧通常有重复的对。
我需要找到一个player_id有多个团队时的所有案例,并打印出来:
2怎么会这样呢?
发布于 2020-12-08 12:53:10
您可以使用nunique()方法对每个组执行groupby并计算唯一值的数量
df.groupby('player_id')['team'].nunique().loc[lambda x: x > 1].indexhttps://stackoverflow.com/questions/65192997
复制相似问题