The second count comes out well, but the descending order doesn't work. Sort() doesn't work
'dict' object has no attribute 'sort'
If you apply sort
, it appears like this.
Dictionaries don't have an order.
If you want to sort, you can change it to a list, but if you wrote a dictionary for the purpose of counting, what's better is the collections counter.
But then again, the ID to count seems to be a column in the data frame. It is best to write value_counts.
id_ounter = df["ID"].value_counts()
Sort and escalating factors can determine whether to sort or not and the direction of sorting.
https://pandas.pydata.org/docs/reference/api/pandas.Series.value_counts.html#
© 2025 OneMinuteCode. All rights reserved.