pandas sample one record per unique value

PHOTO EMBED

Thu Oct 07 2021 01:52:40 GMT+0000 (UTC)

Saved by @aurora1625 #python #pandas

df.groupby('cluster', group_keys=False).apply(lambda df: df.sample(1))
content_copyCOPY