what should i do to remove conceptual duplicates?

Based on the technique in this answer we can get rid of any (player, current_team) combo that exists as a (player, previousteam) combo.

>>> df
   Player CurrentTeam PreviousTeam
0   James      Team A         Null
1   David      Team B         Null
2  George      Team C         Null
3   James      Team B       Team A
4   James      Team C       Team B

>>> old_teams = df[["Player", "PreviousTeam"]].rename(columns={"PreviousTeam": "Team"})
>>> all_teams = df[["Player", "CurrentTeam"]].rename(columns={"CurrentTeam": "Team"})
>>> current_teams = (pd.merge(all_teams, old_teams, indicator=True, how="outer")
                       .query("_merge == 'left_only'")
                       .drop("_merge", axis=1)
>>> current_teams
   Player    Team
0   David  Team B
1  George  Team C
2   James  Team C

CLICK HERE to find out more related problems solutions.

Leave a Comment

Your email address will not be published.

Scroll to Top