I have a dataframe as below:
col1=[1,1,1,2,2,2,3,3,3]
col2=['a','b','c','d','e','f','g','h','i']
col3=[1,2,3,2,3,1,3,1,2]
d={
"col1":col1,
"col2":col2,
"col3":col3
}
dummy= pd.DataFrame(d)
So, the dataframe looks like below:
I want to group all the values according to col1 and get values of col2 according to the sorting(decreasing ord) of col3, i.e, I want my end result as: col2= [c,b,a,e,d,f,g,i,h] I have tried the below which resits in col2 sorted in ascending order:
res=dummy.groupby(['col1','col3'])['col2'].apply(sorted).reset_index()
But the above results in [[a],[b],[c]....]]. I don't want each element to be a list in itself. How do I reverse the order? Any help would be greatly appreciated. Thank you.