Last active
January 14, 2022 17:25
-
-
Save Den1al/af42c2fdc9c2a62a7392816686788450 to your computer and use it in GitHub Desktop.
Pandas collect-set operator on a groupby object
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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