Skip to content

Instantly share code, notes, and snippets.

@kvnkho
Created May 25, 2022 05:33
Show Gist options
  • Select an option

  • Save kvnkho/84e3cb5274e018a51ebf8e4790c88bc0 to your computer and use it in GitHub Desktop.

Select an option

Save kvnkho/84e3cb5274e018a51ebf8e4790c88bc0 to your computer and use it in GitHub Desktop.
# case 1: more shuffle
df.sort_values(["c","d"]).drop_duplicates(subset=["d"], keep="last")
# case 2: less shuffle
idx = df.groupby("d")["c"].idxmax()
df.merge(idx, left_index=True, right_on="c")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment