nunique sort
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
Are there any code examples left?
New code examples in category Python
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