nunique sort

50

df = df.groupby('A')['B'].nunique().sort_values(ascending=False).reset_index(name='count')
print (df)
   A  count
0  D      3
1  C      2
2  E      1

Comments

Submit
0 Comments