filter dataframe after groupby and nunique in pandas

前端 未结 1 531
抹茶落季
抹茶落季 2021-01-16 08:06

i tried df.groupby(\"item\")[\"variable\"].nunique() and it returns a unique count of every item object.

i want to filter to only return the count of \

相关标签:
1条回答
  • 2021-01-16 09:00

    When you want the groupby to be mapped to every row of the input, think about transform:

    df = df[df.groupby("item")["variable"].transform('nunique') > 3]
    
    0 讨论(0)
提交回复
热议问题