I want to sort a nested dict in pyhon via pandas.
import pandas as pd
# Data structure (nested list):
# {
# category_name: [[rank, id], ...],
# ...
# }
all_categories = {
"category_name1": [[2, 12345], [1, 32512], [3, 32382]],
"category_name2": [[3, 12345], [9, 25318], [1, 24623]]
}
df = pd.DataFrame(all_categories.items(), columns=['Category', 'Rank'])
df.sort_values(['Rank'], ascending=True, inplace=True) # this only sorts the list of lists
Can anyone tell me how I can get to my goal? I can't figure it out. Via panda it's possible to sort_values()
by the second column, but I can't figure out how to sort the nested dict/list.
I want to sort ascending by the rank, not the id.