It doesn't apply in descending order.

Asked 2 years ago, Updated 2 years ago, 19 views

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.

python

2022-09-20 11:32

1 Answers

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#


2022-09-20 11:32

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.