I'm trying to count the number of unique items grouped by a value and sorted by the count of the unique items per group.
For example
A B
0 C A
1 C C
2 D C
3 D J
4 D F
5 E C
6 E C
The output should show
A count
0 D 3
1 C 2
2 E 1
I'm currently using the below where I can get the unique count but not the sorting
df.groupby('A').B.nunique()