Suppose I have the following dataframe:
df = pd.DataFrame({'AB': [['ab', 'ef', 'bd'], ['abc', 'efg', 'cd'], ['bd', 'aaaa']],
'CD': [['xy', 'gh'], ['trs', 'abc'], ['ab', 'bcd', 'efg']],
'EF': [['uxyz', 'abc'], ['peter', 'adam'], ['ab', 'zz', 'bd']]})
df
AB CD EF
0 [ab, ef, bd] [xy, gh] [uxyz, abc]
1 [abc, efg, cd] [trs, abc] [peter, adam]
2 [bd, aaaa] [ab, bcd, efg] [ab, zz, bd]
I want to extract the column which contains a sorted list. In this case it is CD, since ['ab','bcd','efg']
is sorted in ascending order. It is guaranteed that no list is empty and it will contain at least two elements. I am stuck at how to combine applymap
and sort
function together using Pandas ?
I tried to come up with the solution from here but couldn't figure out a way to combine applymap
and sort
.
I am working in Python 2.7 and pandas