python - Sort a list of entries according to a given column and return the list of indices -
given list of entries (e.g. pieces of data, tuples), how sort list according 1 column (feature, e.g. int) , return not entire sorted list of entries, list of original indices (like in function np.argsort()
)?
i tried use lambda expressions not know how incoporate indices feature:
list1sorted=sorted(list1, key=lambda x: x[1])
import pandas pd lst = [13,6,3,2,1,7,6,8] othr = [5,2,7,9,2,5,7,10] df = pd.dataframe({"list1": lst, "list2": othr}) result = df.sort_values("list1")
here ldf contain 2 lists, sorted list1 , can find indices index (result.index
) of dataframe.
Comments
Post a Comment