Here is the code:
test = pd.DataFrame({'country':['us','ca','ru','cn','ru','cn','us','ca','ru','cn','us','ca','ru','cn','us','ca'], 'month':[5,6,7,5,6,7,5,5,6,7,5,6,6,5,5,6], 'id':[x for x in range(16)]})
p = test.pivot_table(index=['month', 'country'], aggfunc='count')[['id']]
The output looks like this:
I'd like to sort the table by the id
column, so that the largest number appear on top like:
id
month country
us 4
5 cn 2
ca 1