Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ID, ATTRIBUTE
- 1, thing2
- 1, thing3
- 1, thing3
- 2, thing7
- 2, thing7
- 2, thing2
- 3, thing1
- 3, thing2
- mode = lambda x: x.mode() if len(x) > 2 else 'multithing'
- df_grouped = df.groupby(['ID'], as_index=False)['ATTRIBUTE].agg(mode)
- ID, ATTRIBUTE
- 1, thing3
- 2, thing7
- 3, multithing
- df_final.groupby('ATTRIBUTE')['ID'].count()
Add Comment
Please, Sign In to add comment