我可以列出
mylist = [0.1,0.2,-.09,-.9,0.001,-0.001,0.05,-0.05,.9,.8,-.7] 使用功能 AltSignSort (我的列表)对该列表进行排序,并获得:
请注意,该列表是按交替符号w /从0到最小的最大位移进行排序的(此功能如下)。
我想要执行的是pandas df的列排序(如上述方式)。例如,df.corr()给出矩阵的成对相关。是否有可能以这种方式对其列进行排序。谢谢。
def AltSignSort(array):
# Assistance was recieved at https://www.geeksforgeeks.org/
# This code is inspired by an example given by Arnab Kundu
# sort the array in ascending order
array.sort()
# get index to first element of the list
first = 0
first = first + 1
index = 1
while ( index < (len(array) + 1)/2 ):
index = index + 1
# pop last element in the array
val = array[-1]
array.pop()
# insert it after next minimum element
array.insert(first, val)
# increment the pointer for next pair
first = first + 2
return(array)'''