Here is an example of what it means:
Data:
import pandas as pd
df = pd.DataFrame(data={"cost": [30, 29, 40, 45, 240, 200, 220, 180, 150, 130],
"date": [ "2017-11-01", "2016-12-01", "2016-11-01",
"2017-12-01", "2018-11-30", "2018-12-01",
"2019-11-30", "2019-12-30", "2020-11-30",
"2020-12-30"]})
df["date"] = pd.to_datetime(df["date"])
df.set_index("date", inplace=True)
print(df)
# cost
#date
#2017-11-01 30
#2016-12-01 29
#2016-11-01 40
#2017-12-01 45
#2018-11-30 240
#2018-12-01 200
#2019-11-30 220
#2019-12-30 180
#2020-11-30 150
#2020-12-30 130
Notice that the first date is 2017.
With sort=False 2017 is still the first row:
df.groupby([lambda x: x.year], sort=False).count()
#Out:
# cost
#date
#2017 2
#2016 2
#2018 2
#2019 2
#2020 2
As the default is sort=True, 2017 is no longer first, as the dates are sorted:
df.groupby([lambda x: x.year]).count()
#Out:
# cost
#date
#2016 2
#2017 2
#2018 2
#2019 2
#2020 2
Without sorting (sort=False), the groups are in the order of first appearance in the row. With sorting (sort=True or not given), the groups will be sorted as Python sorts, i.e. numerically, alphabetically etc.