'pandas sort values of groupby

I have a set of data about football:

dataset

I sorted it by how many matches were played at each ground:

fb2 = fb.groupby(by=['Ground'])['Ground'].count()
print(fb2)

Output:

Ground
Aberdeen         11
Abu Dhabi        37
Adelaide         82
Ahmedabad        24
Albion            5
                 ..
Vijayawada        1
Visakhapatnam    11
Wellington       56
Whangarei         1
Worcester         3
Name: Ground, Length: 173, dtype: int64

Now I want to sort the results, in descending order of how many matches were played at each ground.

I am very new to python...any help would be much appreciated!



Solution 1:[1]

The type of fb.groupby(by=['Ground'])['Ground'].count() is Series, you can sort it using pandas.Series.sort_values()

fb.groupby(by=['Ground'])['Ground'].count().sort_values(ascending=False))

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Ynjxsjmh