Skip to content

Instantly share code, notes, and snippets.

@Den1al
Last active January 14, 2022 17:25
Show Gist options
  • Save Den1al/af42c2fdc9c2a62a7392816686788450 to your computer and use it in GitHub Desktop.
Save Den1al/af42c2fdc9c2a62a7392816686788450 to your computer and use it in GitHub Desktop.
Pandas collect-set operator on a groupby object
# author: @Daniel_Abeles
# date: 13/02/2018
# assuming we have a data frame called "df"
# we can "groupby" by a column col1
# and collect all the distinct values of col2
df.groupby("col1").agg({
"col2": lambda x: set(x)
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment