Entering edit mode
5.5 years ago
xupbuy
▴
30
I have a dictionary:
d = {'b':1, 'a':3, 'aa':12,'c':24, 'bb':31,'abc':123}
I have a list containing keys:
l = ['a','c','b','abc','bb','aa']
How to sort d1 based on l in python (or pandas)? I want the keys in d1 to be sorted in the order in l.
d_sorted = {'a':3,'c':24, 'b':1,'abc':123, bb':31,'aa':12'}
Thank you.